Quick viewing(Text Mode)

City Basics Youtube Youtube.Com/Daggerfallworkshop V1.3.31 [Unity 5.0.1] | 06/08/2015 Twitter Twitter.Com/Gav Clayton Email [email protected]

City Basics Youtube Youtube.Com/Daggerfallworkshop V1.3.31 [Unity 5.0.1] | 06/08/2015 Twitter Twitter.Com/Gav Clayton Email Interkarma@Dfworkshop.Net

Devblog dfworkshop.net Forums forums.dfworkshop.net Daggerfall Tools for Unity Tutorial Source github.com/Interkarma/daggerfall-unity City Basics YouTube .com/daggerfallworkshop V1.3.31 [Unity 5.0.1] | 06/08/2015 Twitter twitter.com/gav_clayton Email [email protected]

City Basics

Introduction

This tutorial builds on concepts introduced in Dungeon Basics. It assumes you now have some familiarity with the Unity Editor and Daggerfall Tools for Unity.

In this tutorial, we will import the city of Daggerfall, add a sky background, change time and seasons, enter buildings and dungeons, and open and close city gates. Let’s get to it!

Getting Started

Please create a new project and scene by following the Getting Started tutorial. To summarise:

 Note: You must be running Unity 5.0.1 or later.  Create a New Project and import Custom Package “Daggerfall Tools for Unity.unitypackage”.  Empty default scene and add DaggerfallUnity and Player (or PlayerAdvanced) prefabs.  Prepare Lighting configuration and set player Rendering Path to Deferred.  Set Quality settings to Fantastic.  Set Arena2 Path of your local Daggerfall installation.  Create Run input binding and optionally invert mouse look.

Import Daggerfall City

Go to the Daggerfall Unity Importer foldout and enter Daggerfall/Daggerfall into City Name (this field is case sensitive) then click Import.

This will take a few seconds to read and convert data from Daggerfall’s into your Unity scene. When finished, you should have a completed scene like below. Devblog dfworkshop.net Forums forums.dfworkshop.net Daggerfall Tools for Unity Tutorial Source github.com/Interkarma/daggerfall-unity City Basics YouTube youtube.com/daggerfallworkshop V1.3.31 [Unity 5.0.1] | 06/08/2015 Twitter twitter.com/gav_clayton Email [email protected]

Above: Daggerfall City consists of 8x8 exterior block elements.

Adding Sunlight

To add sunlight, drag and drop the Sunlight Rig from Prefabs/World into your Hierarchy. This will add more light using a simple three-point directional light setup. The Sunlight Rig prefab also has some automation we’ll look at in a few minutes.

Devblog dfworkshop.net Forums forums.dfworkshop.net Daggerfall Tools for Unity Tutorial Source github.com/Interkarma/daggerfall-unity City Basics YouTube youtube.com/daggerfallworkshop V1.3.31 [Unity 5.0.1] | 06/08/2015 Twitter twitter.com/gav_clayton Email [email protected]

Note: Daggerfall Tools for Unity uses the Unity 5 Standard Shader for almost all materials. This means you can use Physically Based Shading, skyboxes, realtime GI, and other advanced lighting methods. However, this tutorial only covers basic lighting for simplicity.

Position Player

Select the Player object in Hierarchy and set their transform as below.

This positions your player in the main thoroughfare facing Daggerfall Castle. Hit Play and have a brief explore. When you’re done, press Play again to exit play mode.

Add Sky Background

Now we have a city to explore, but the sky is completely dark. Let’s go through the steps of adding a sky to our scene. There is a SkyRig prefab for you in Prefabs/World. But rather than just drop in a prefab, we’ll go through the steps of adding a sky manually to see how it works.

Click GameObject > Create Empty and rename it CitySky.

With CitySky selected, add the Daggerfall Sky component. This also adds a secondary Camera component for the sky renderer which you can ignore.

 Sky Index is a number between 0-31 controlling the sky to be displayed. Daggerfall uses a variety of sky images to represent different climates, seasons, and weather. Devblog dfworkshop.net Forums forums.dfworkshop.net Daggerfall Tools for Unity Tutorial Source github.com/Interkarma/daggerfall-unity City Basics YouTube youtube.com/daggerfallworkshop V1.3.31 [Unity 5.0.1] | 06/08/2015 Twitter twitter.com/gav_clayton Email [email protected]

 Sky Frame is a number between 0-63 controlling the sky animation. There are 32 frames of animation from dawn to midday, where the skies are flipped east-to-west then those animations are played backwards from midday to dusk. DaggerfallSky takes care of all the animation and flipping. Just think of a complete day cycle having 64 frames of animation. For Daggerfall’s 12-hour daylight period, this is equivalent to 1 step every 11.25 minutes.  Is Night will exchange the sky for a static night time version. Night skies have only a single frame, so Sky Frame will be ignored until Is Night is cleared.  Show Stars will toggle a random star field in night skies.  Sky Tint Color will colourize the sky in realtime. This is useful for creating a variety of effects. Default is 128, 128, 128, 255 for R, G, B, A values.  Sky Color Scale is the overall brightness of the sky in realtime. This is handy if you need to darken the sky (e.g. a partial blindness debuff) or ramp it up extra-bright (e.g. lightning flashes).  Weather Style sets optional overcast textures. Just leave this on Normal for now.

Click Play now and your sky will be rendered to the background under other geometry.

Above: Sky background added to scene.

Changing Time & Seasons

You may have noticed a few check boxes in the DaggerfallUnity singleton about automating time and space. These options indicate the tools should automatically swap textures and other settings to handle day/night and seasonal transitions. Devblog dfworkshop.net Forums forums.dfworkshop.net Daggerfall Tools for Unity Tutorial Source github.com/Interkarma/daggerfall-unity City Basics YouTube youtube.com/daggerfallworkshop V1.3.31 [Unity 5.0.1] | 06/08/2015 Twitter twitter.com/gav_clayton Email [email protected]

With automation enabled, many of the components in Daggerfall Tools for Unity are able to perform texture swaps and other changes to simulate time of day and passing of the seasons. The key to this automation lies in the World Time component on the DaggerfallUnity singleton.

If you can’t see all settings above, expand the World Date Time field. These values represent the exact in-game time down to the second. These fields are all zero-based, which means the 12 months of the year are represented by 0-11, the 24 hours of the day are 0-23, etc.

The first thing we’ll do is change the season to one of the winter months. To do this, simply edit the Month field to 12, which corresponds to Evening Star (or December on Earth). Hit Play and your game world is plunged into winter. When you’re done exploring, press Play again and return to editing.

The next thing to try changing is the time of day. Set the Hour field to 0 (midnight) and go into Play mode again. We now have a night-time winter scene.

Above: A winter scene. Above: Night-time in winter.

Devblog dfworkshop.net Forums forums.dfworkshop.net Daggerfall Tools for Unity Tutorial Source github.com/Interkarma/daggerfall-unity City Basics YouTube youtube.com/daggerfallworkshop V1.3.31 [Unity 5.0.1] | 06/08/2015 Twitter twitter.com/gav_clayton Email [email protected]

Now set the Month back to 5 and Hour back to 12 (or just reset World Time back to prefab settings).

The final thing we can try is changing the Time Scale to watch day-night transitions. Set this to a high value like 2000 and Play the game again. You can now watch shadows creep across the ground, lights turn on and off, and day follow night.

If you’d like to see the current time then enable Show Debug String to display the time on-screen.

Don’t forget to reset your Time Scale back to 10 or revert World Time to prefab before moving on.

Building Interiors

Let’s explore inside those buildings! The transition between outside and inside is handled by several different components all working together.

 DaggerfallStaticDoors. This component was imported along with the city. Every building (or block when using RMB combining) contains a list of doors the player can use to enter/exit buildings and dungeon.  PlayerActivate. This script detects when the player clicks on things. In this case, it will handle the player clicking on doors.  PlayerEnterExit. This script transitions player in and out of buildings and dungeons. There are a few options here to help you build dynamic, compartmentalized scenes. We will look at these more closely in a moment.  DaggerfallInterior. This script handles the layout of a new interiors at runtime. It would be far too memory-intensive to load every interior from the editor. Instead we only load them as needed, just like Daggerfall.  GameObjectHelper. This script is filled with static helper objects to construct new scene data dynamically. It is used heavily by the editor when importing scenes, but you can also use this script to import anything at runtime as well. If you ever need to load a Daggerfall game object at runtime, there is probably a helper for it here.  PlayerGPS. Provides information about player’s position in world space for texture swaps and dungeon transitions. We’ll touch on more in a few minutes.

Before we can enter buildings there are a few scripts required by our player. Select Player in Hierarchy then click Add Component in its Inspector.

Add the Scripts > DaggerfallWorkshop.Demo > Player Activate component. We looked at this script in the Dungeon Basics tutorial. It is responsible for detecting clicks on world objects like doors and switches.

With Player still selected in Hierarchy add component Scripts > DaggerfallWorkshop.Demo > Player Enter Exit. This script transitions player in and out of buildings. Let’s take a closer look. Devblog dfworkshop.net Forums forums.dfworkshop.net Daggerfall Tools for Unity Tutorial Source github.com/Interkarma/daggerfall-unity City Basics YouTube youtube.com/daggerfallworkshop V1.3.31 [Unity 5.0.1] | 06/08/2015 Twitter twitter.com/gav_clayton Email [email protected]

 Exterior Parent is a parent GameObject to be disabled/enabled as player enters/exits buildings. This is done so you can rig up lighting and other effects to the outside exclusive from the inside. It also prevents the exterior and interior being active at the same time.  Interior Parent is a parent GameObject to be enabled/disabled as the player enters/exits buildings.  Dungeon Parent is the parent GameObject for dungeons. We’ll setup a dungeon transition so we can explore Daggerfall Castle.  Override Location allows us to override PlayerGPS in standalone scenes. We will look at this in more detail towards end of tutorial.

Before we can enter and exit buildings, we need to do a bit of scene preparation. It’s important to keep our scene neatly arranged so interior and exterior environments don’t appear together at the same time.

Click on menu GameObject > Create Empty to create a new game object in your Hierarchy. Rename it to ExteriorParent and reset its Transform property in Inspector (click cog next to its Transform then Reset from drop-down menu). When you’re done, the ExteriorParent game object should have a reset Transform like below.

In Hierarchy, drag and drop game objects DaggerfallCity [Region=Daggerfall, Name=Daggerfall], CitySky, and SunlightRig directly onto ExteriorParent object to make them a child of ExteriorParent. Your Hierarchy should now resemble the below image. Devblog dfworkshop.net Forums forums.dfworkshop.net Daggerfall Tools for Unity Tutorial Source github.com/Interkarma/daggerfall-unity City Basics YouTube youtube.com/daggerfallworkshop V1.3.31 [Unity 5.0.1] | 06/08/2015 Twitter twitter.com/gav_clayton Email [email protected]

Now click on GameObject > Create Empty again to create another empty game object. Call this one InteriorParent and reset its transform like above. It’s important to reset the Transform, this ensures building interiors will line up with the exterior correctly. This is not critical for transitions to work but can help with checking interiors in the editor as they appear where the building is located. Your Hierarchy should now look like below.

Finally, create a DungeonParent and reset its Transform like above.

Devblog dfworkshop.net Forums forums.dfworkshop.net Daggerfall Tools for Unity Tutorial Source github.com/Interkarma/daggerfall-unity City Basics YouTube youtube.com/daggerfallworkshop V1.3.31 [Unity 5.0.1] | 06/08/2015 Twitter twitter.com/gav_clayton Email [email protected]

The next step is to inform our PlayerEnterExit script about the parent game objects. In Hierarchy click on Player then find PlayerEnterExit in Inspector.

Click on the little circle to the right of Exterior Parent and select the ExteriorParent game object from the Scene tab. You can use the search box to help locate the right game object like below.

Alternatively, you could also drag and drop the ExteriorParent game object directly onto the Exterior Parent field in Inspector.

Next, set InteriorParent in the Interior Parent field in Inspector by using search circle as above or by dragging and dropping.

Finally, set DungeonParent in the Dungeon Parent field. When you’re done, your PlayerEnterExit component should look like below.

We have now created parent game objects for exterior and interior scenes, and informed PlayerEnterExit which parent is responsible for which compartment of the scene.

Before we finish, you must disable the InteriorParent and DungeonParent game object from its Inspector by deselecting the check box next to its name. Parent objects will be enabled and disabled automatically as required. This is very important to maintain clean separation of game areas.

Devblog dfworkshop.net Forums forums.dfworkshop.net Daggerfall Tools for Unity Tutorial Source github.com/Interkarma/daggerfall-unity City Basics YouTube youtube.com/daggerfallworkshop V1.3.31 [Unity 5.0.1] | 06/08/2015 Twitter twitter.com/gav_clayton Email [email protected]

Above: Clear the InteriorParent and DungeonParent enable boxes in their Inspector.

You’re now ready to hit Play and start exploring inside buildings. There’s just one more problem we need to take care of, which you will notice the first time you go into a building.

Above: Interior is dark because there are no lights assigned to InteriorParent. The fireplace uses an unlit texture and will always appear evenly bright.

In Daggerfall, interiors of buildings need only basic lighting. There is an interior light prefab provided in Prefabs > World > InteriorLightRig. This is basically a non-automated version of our SunlightRig prefab.

Drag and drop the InteriorLightRig onto your InteriorParent in Hierarchy. This will create a basic lighting setup for all interior zones. Your Hierarchy should now look like below. Devblog dfworkshop.net Forums forums.dfworkshop.net Daggerfall Tools for Unity Tutorial Source github.com/Interkarma/daggerfall-unity City Basics YouTube youtube.com/daggerfallworkshop V1.3.31 [Unity 5.0.1] | 06/08/2015 Twitter twitter.com/gav_clayton Email [email protected]

Note that InteriorParent, its child InteriorLightRig, and DungeonParent are all dimmed, as yours should be. This means they are currently disabled. It is important to disable InteriorParent and DungeonParent or any lighting effects will also be applied to exterior scene. If your scene is washed out and overbright, you may have forgotten to disable these parent game objects.

That should do the trick. Enter Play mode again and your Interiors should be lit similar to Daggerfall.

Above: The interior is now lit by the InteriorLightRig we added to InteriorParent.

When you click on the exit door, our PlayerEnterExit script will transition player back outside and set enable states on parents as required.

Go ahead and explore. If you enter Play mode with Hierarchy visible, you will see the ExteriorParent and InteriorParent game objects become enabled/disabled as PlayerEnterExit handles transitions.

Devblog dfworkshop.net Forums forums.dfworkshop.net Daggerfall Tools for Unity Tutorial Source github.com/Interkarma/daggerfall-unity City Basics YouTube youtube.com/daggerfallworkshop V1.3.31 [Unity 5.0.1] | 06/08/2015 Twitter twitter.com/gav_clayton Email [email protected]

Dungeon Interiors

If you stole a peek inside Daggerfall Castle, you will have noticed something very wrong. For some reason, Privateer’s Hold was loaded instead!

The reason this happened is because dungeon interiors are not explicitly linked to the exterior map. Daggerfall stores them as two separate maps linked together by virtue of sharing the same world cell position. In Daggerfall Tools for Unity, this is called MapPixelX and MapPixelY. These correspond to X, Y coordinates on a Daggerfall 1000x500 world map.

Above: The 1000x500 small height map data with the city of Daggerfall highlighted in red at coordinates 207, 213. Daggerfall has multiple 1000x500 maps for different purposes. Reading this data is handled for you by the underlying API.

When exploring a fully procedural world (covered in the Streaming World intermediate tutorial), the player’s position is synced with PlayerGPS, enabling PlayerEnterExit to always load the correct dungeon interior. However in this tutorial, we have imported a city manually into a standalone scene so there is nothing to inform PlayerGPS about the player’s location. Fortunately there are a couple of methods to fix this in standalone scenes.

Method 1 – Set PlayerGPS Position

The most obvious fix is to inform PlayerGPS about where the player is in the world based on the city we manually imported. What we need to do is get the world coordinates of Daggerfall city and feed those into PlayerGPS.

First, click on DaggerfallLocation [Region=Daggerfall, Name=Daggerfall] in Hierarchy. Your Inspector will then tell us everything we need to know about Daggerfall city. Let’s take a look at these properties in more detail. Devblog dfworkshop.net Forums forums.dfworkshop.net Daggerfall Tools for Unity Tutorial Source github.com/Interkarma/daggerfall-unity City Basics YouTube youtube.com/daggerfallworkshop V1.3.31 [Unity 5.0.1] | 06/08/2015 Twitter twitter.com/gav_clayton Email [email protected]

 ID is a unique identifier read from the game files.  Longitude, Latitude, Map X, Map Pixel Y, World Coord X, World Coord Z are different coordinates of this location.  World Climate is the climate index read from CLIMATE.PAK at this map pixel position.  Sky Base is the base sky index before any season or weather modifiers are applied.  Region Name is the province or region the location was imported from.  Location Name is the name of the city or dungeon imported.  Has Dungeon is a flag showing if this location has a dungeon map associated with it. In this case, the city of Daggerfall has a dungeon inside the main castle.  Climate Base is the base climate (without any seasonal modifier applied) for this location.  Nature Flats are the billboard rocks, trees, etc. scattered around for this location’s climate.  Usage allows you to control the climate settings. You can either use the location’s climate settings, set your own custom climate, or disable climate processing entirely.  Season will change between summer and winter textures.  Windows will set the window palette swaps. You can use a few presets or set your own custom colours. The window properties are controlled by the MaterialReader component attached to the DaggerfallUnity singleton.  Apply will apply your climate changes to the scene.

Note: We’re not going to worry about changing the climate here, but go ahead and experiment with this if you like. To keep your climate changes in Play mode, disable Automate Textures in Time & Space options of DaggerfallUnity. This will prevent the texture automation from changing your climate settings at runtime based on time of year, etc. Devblog dfworkshop.net Forums forums.dfworkshop.net Daggerfall Tools for Unity Tutorial Source github.com/Interkarma/daggerfall-unity City Basics YouTube youtube.com/daggerfallworkshop V1.3.31 [Unity 5.0.1] | 06/08/2015 Twitter twitter.com/gav_clayton Email [email protected]

The fields we are most interested in right now are the World Coord X and World Coord Z values. These are the same coordinates our PlayerGPS uses.

To manually set your world position, select your Player in Hierarchy then edit PlayerGPS in Inspector so the world coordinates match those of Daggerfall city as shown above.

So your PlayerGPS should now have a World X value of 6782976 and a World Z value of 9371648 like below.

With that done, jump back into Play mode and your game will now load the correct dungeon interior when entering Daggerfall Castle.

Note: PlayerEnterExit also uses PlayerGPS coordinates to set the interior textures of buildings based on the climate of player’s current world location.

Method 2 – Use Override Location

If setting up PlayerGPS feels like too much work, there’s a much simpler method to override the player’s location in standalone scenes.

To do this, first select the Player object in Hierarchy and look for the Override Location field under PlayerEnterExit in Inspector.

Now simply drag DaggerfallLocation [Region=Daggerfall, Name=Daggerfall] from Hierarchy onto the Override Location field in Inspector. Your PlayerEnterExit should now look like below.

Note: You can also click the little circle to the right of Override Location field and select from list. Devblog dfworkshop.net Forums forums.dfworkshop.net Daggerfall Tools for Unity Tutorial Source github.com/Interkarma/daggerfall-unity City Basics YouTube youtube.com/daggerfallworkshop V1.3.31 [Unity 5.0.1] | 06/08/2015 Twitter twitter.com/gav_clayton Email [email protected]

With that done, go into Play mode and the correct dungeon will be loaded when entering Daggerfall Castle. When Override Location set, PlayerGPS coordinates are completely ignored by PlayerEnterExit.

Close City Gates

Currently the player is free to explore outside the city bounds and potentially fall off the edge of the map.

If you would like to confine player to within city limits, you can close the city gates in one of two ways.

The first is to enable Close City Gates from Import Options of DaggerfallUnity singleton. This must be done before importing your city location.

Alternatively, you can select each city gate in your scene and use the Toggle Gate button in Inspector to open & close them.

For advanced users, you can open and close gates at runtime using the DaggerfallCityGate.Toggle() method from script.

Devblog dfworkshop.net Forums forums.dfworkshop.net Daggerfall Tools for Unity Tutorial Source github.com/Interkarma/daggerfall-unity City Basics YouTube youtube.com/daggerfallworkshop V1.3.31 [Unity 5.0.1] | 06/08/2015 Twitter twitter.com/gav_clayton Email [email protected]

Conclusion

This concludes the City Basics tutorial. If you feel like experimenting further, here are some things to try.

 Disable Automate Textures in Time & Space options of DaggerfallUnity and play with the custom climate settings of Daggerfall Location.  Setup the Player as you did in Dungeon Basics (with weapons, etc.) and go exploring in Daggerfall Castle. Alternatively, replace Player with PlayerAdvanced which has most setup done for you.  Drop some enemies around the city using Prefabs/Scene/Daggerfall Enemy prefab. You just need to drag and drop prefab into scene, select then apply an enemy type, then align to ground. Try adding lots of imps and bats to pursue the player. Note: This prefab will be covered in more detail in the Prefab Basics tutorial.  Delete your Daggerfall Location and add a different location such as Wayrest/Wayrest. You can use the Daggerfall Tools > Atlas menu to browse for valid locations by region and type. Don’t forget to make your imported location a child of ExteriorParent object, and to set Override Location or PlayerGPS coordinate.  Write a component to open and close city gates at dawn and dusk.