Dungeon Basics - dfworkshop.net Tools for Unity... · Daggerfall Tools for Unity Tutorial Dungeon...

14
Daggerfall Tools for Unity Tutorial Dungeon Basics V1.3.31 [Unity 5.0.1] | 06/08/2015 Devblog dfworkshop.net Forums forums.dfworkshop.net Source github.com/Interkarma/daggerfall-unity YouTube youtube.com/daggerfallworkshop Twitter twitter.com/gav_clayton Email [email protected] Dungeon Basics Introduction In this tutorial, we will use the Unity Editor to recreate Daggerfall’s starting dungeon Privateer’s Hold. We will then setup a melee-ready player character with one or two weapons equipped. The player character will also be capable of opening doors, fighting monsters, flipping switches, and riding moving platforms. 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 Privateer’s Hold Go to the Daggerfall Unity Importer foldout and enter Daggerfall/Privateer’s Hold into Dungeon Name (this field is case sensitive) then click Import. This will take a few seconds to read and convert data from Daggerfall’s files into your Unity scene. When finished, you should have a completed scene like below.

Transcript of Dungeon Basics - dfworkshop.net Tools for Unity... · Daggerfall Tools for Unity Tutorial Dungeon...

Daggerfall Tools for Unity Tutorial Dungeon Basics V1.3.31 [Unity 5.0.1] | 06/08/2015

Devblog dfworkshop.net Forums forums.dfworkshop.net Source github.com/Interkarma/daggerfall-unity YouTube youtube.com/daggerfallworkshop Twitter twitter.com/gav_clayton Email [email protected]

Dungeon Basics

Introduction

In this tutorial, we will use the Unity Editor to recreate Daggerfall’s starting dungeon Privateer’s

Hold. We will then setup a melee-ready player character with one or two weapons equipped. The

player character will also be capable of opening doors, fighting monsters, flipping switches, and

riding moving platforms.

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 Privateer’s Hold

Go to the Daggerfall Unity Importer foldout and enter Daggerfall/Privateer’s Hold into Dungeon

Name (this field is case sensitive) then click Import.

This will take a few seconds to read and convert data from Daggerfall’s files into your Unity scene.

When finished, you should have a completed scene like below.

Daggerfall Tools for Unity Tutorial Dungeon Basics V1.3.31 [Unity 5.0.1] | 06/08/2015

Devblog dfworkshop.net Forums forums.dfworkshop.net Source github.com/Interkarma/daggerfall-unity YouTube youtube.com/daggerfallworkshop Twitter twitter.com/gav_clayton Email [email protected]

Above: Privateer’s Hold. The loose bits of dungeon suspended in mid-air are from “border” blocks which seal off “normal”

dungeon blocks from all sides. You can read more about dungeon block layouts on UESP from the following link.

http://www.uesp.net/wiki/Daggerfall:Dungeons

Player Character

During setup, we added a basic player prefab from the Daggerfall Unity/Prefabs/Player folder. If

you want to create your own player controller (e.g. using UFPS or similar), you should first study this

prefab controller to understand which settings have been made to help player fit to environment.

In this tutorial, we will be using the prefab Player as it’s already tuned for Daggerfall’s environments.

The prefab player includes a PlayerMotor script capable of riding moving platforms.

Select the Player prefab in your Hierarchy panel then set its position to 12.75, 1, 41.8 in Inspector as

shown below. This positions our player on top of the Enter marker in Privateer’s Hold.

Save your scene with File > Save Scene then click the Play button. You should have a basic player

controller capable of moving around with mouse look and W, S, A, D keys for movement.

Daggerfall Tools for Unity Tutorial Dungeon Basics V1.3.31 [Unity 5.0.1] | 06/08/2015

Devblog dfworkshop.net Forums forums.dfworkshop.net Source github.com/Interkarma/daggerfall-unity YouTube youtube.com/daggerfallworkshop Twitter twitter.com/gav_clayton Email [email protected]

When you’re done experimenting, tap your Esc Key to uncapture mouse and click Play button again

to end play mode and return to editing your scene.

Player Actions

If you ventured out from the starting cave, you would have encountered a door blocking your path.

To open this door, we need to add the script responsible for player actions.

Inside the Daggerfall Unity/Scripts/Demo folder in Project are several scripts for handling more

complicated jobs. We will use one of these to imbue player with the power to open doors. There are

many interesting scripts inside this folder for different tasks, and you are encouraged to examine

these to learn how certain things are achieved. For now, we just want the player to open doors.

Select your Player object in Hierarchy then click Add Component in Inspector.

Enter “player activate” in search field then click Player Activate script in search results.

Alternatively, you can click Add Component in Inspector (still with Player selected in Hierarchy) and

navigate to Scripts > DaggerfallWorkshop.Demo > PlayerActivate.

Once the component is added, you should have a single Player Activate (Script) attached to your

Player game object in Inspector.

Click Play and go exploring. You should now be able to use Fire1 key bind (default is left-click) to

open the door out of starting tunnel. If you venture outside the starting area, you will encounter a

vicious giant rat. Unfortunately you have no way of fighting back yet.

Note: PlayerHealth and ShowPlayerDamage are now a default part of included player prefabs. If you

did not start with a prefab, you will need to add these components to your player.

Daggerfall Tools for Unity Tutorial Dungeon Basics V1.3.31 [Unity 5.0.1] | 06/08/2015

Devblog dfworkshop.net Forums forums.dfworkshop.net Source github.com/Interkarma/daggerfall-unity YouTube youtube.com/daggerfallworkshop Twitter twitter.com/gav_clayton Email [email protected]

Player Weapons

Let’s put down that rat! Our first job is to add the WeaponManager script from Scripts/Demo to

your Player object, just like we did for the PlayerActivate script above.

There are a few properties here that are not immediately clear. Before proceeding, let’s take a

minute to study them and understand what they do.

Left Hand Weapon and Right Hand Weapon are simple enough. These are the FPSWeapon game

objects which handle weapon animations and other details. You can have one per hand for dual-

wielding. We’ll get to these in a minute.

Sheathed is simply a flag used to hide/show weapons. The WeaponManager script uses the Z key to

sheath/unsheathe weapons.

Sphere Cast Radius is used by the physics system to detect if weapons have struck anything. A

sphere cast is used over a ray cast to be more forgiving of target placement. A larger sphere radius

will allow the player to hit things at wider angles during combat.

Horizontal Threshold and Vertical Threshold are speed values used by the gesture attack system.

The mouse must change a minimum of this value (which is best thought of as a speed value from 0-

1) before an attack gesture is registered. If you would like attacks to register with less movement of

the mouse, lower this value.

Trigger Count is the number of updates in a row the thresholds must be met before an attack

gesture fires. This prevents attacks from immediately registering the first direction detected, as this

may not be the direction your player is actually trying to gesture in. Increasing this value will make

attacks more “laggy”, lowering it will make gestures more “twitchy”.

Chance To Be Parried is a fake gameplay stat used to determine how often enemies will deflect your

attacks. This would normally be part of true combat mechanics and is here only for example

purposes. A successful parry will play one of several parry sound effects and block incoming damage

to enemies. Set this to 0 if implementing real gameplay.

For now, just leave all the values of WeaponManager as they are. The next step is to create a

weapon for the player.

Daggerfall Tools for Unity Tutorial Dungeon Basics V1.3.31 [Unity 5.0.1] | 06/08/2015

Devblog dfworkshop.net Forums forums.dfworkshop.net Source github.com/Interkarma/daggerfall-unity YouTube youtube.com/daggerfallworkshop Twitter twitter.com/gav_clayton Email [email protected]

Select your Player object in Hierarchy then click GameObject > Create Empty Child. This will create a

blank game object under your player. Right-click and rename this child to Right Hand Weapon.

With Right Hand Weapon selected in Hierarchy add script FPSWeapon from the Scripts/Demo

folder. This will also add required components AudioSource and DaggerfallAudioSource. These

components are used to play back weapon sounds. Ignore them for now and let’s have a closer look

at the properties of FPSWeapon.

Show Weapon toggles weapon visibility on and off. The WeaponManager we setup previously will

toggle this based on Sheathed property.

Left Hand will flip animations where appropriate to make weapon appear to be in the player’s left

hand. Don’t click this option yet, as we’re creating the right hand weapon.

Weapon Type and Metal Type determine the animations and palette swaps used to render your

weapon. You can change this to any melee weapon combination you like. Avoid hand-to-hand (fists

and werecreature) and ranged weapons (bow) for now as these are not fully implemented as of

version 1.3.x.

Range is the maximum distance the weapon can strike an enemy. This is modified by the Sphere

Cast Radius (on WeaponManager above) to prevent weapon gaining extra reach from hit checks.

Min Damage and Max Damage represent the damage range transferred to enemies on a successful

hit. Unlike the player, enemies have a basic health model and can be killed.

Attack Speed Scale will increase or decrease the speed of weapon swings.

Draw Weapon Sound is a sound effect enumeration for the sound played when player unsheathes

their weapon.

Swing Weapon Sound is a sound effect enumeration for the sound played when the player swings

their weapon. The pitch of this sound is modulated based on Attack Speed Scale so that slow

weapons make a deeper sound and fast weapons make a higher-pitched sound. This is how

Daggerfall handles this also.

Daggerfall Tools for Unity Tutorial Dungeon Basics V1.3.31 [Unity 5.0.1] | 06/08/2015

Devblog dfworkshop.net Forums forums.dfworkshop.net Source github.com/Interkarma/daggerfall-unity YouTube youtube.com/daggerfallworkshop Twitter twitter.com/gav_clayton Email [email protected]

Now that a weapon is created, we need to add it to our player. Go back to WeaponManager (by

selecting Player in Hierarchy) and click the little circle to the right of the Right Hand Weapon field in

its Inspector. This will allow you to select the Right Hand Weapon game object we just created.

Double-click the below to select weapon and close popup.

Once this has been selected, your WeaponManager component should resemble below.

We have now added a WeaponManager, created a Right Hand Weapon game object, and assigned

that game object to your player. Click Play and your weapon should now be visible and have full

Daggerfall-styled attacks available. Hold down Fire2 key bind (default is right mouse button) and

take a few practice swings. Go kill that rat if you like!

Dual Wielding

As an added bonus, let’s enable dual-wielding for your player. The first thing we need is a second

weapon object.

Click on your Player in Hierarchy then click GameObject > Create Empty Child. Rename this game

object to Left Hand Weapon and attach FPSWeapon component. Setup your new weapon however

you like, but remember to select the Left Hand tick box (see below) so the animations are correct.

Daggerfall Tools for Unity Tutorial Dungeon Basics V1.3.31 [Unity 5.0.1] | 06/08/2015

Devblog dfworkshop.net Forums forums.dfworkshop.net Source github.com/Interkarma/daggerfall-unity YouTube youtube.com/daggerfallworkshop Twitter twitter.com/gav_clayton Email [email protected]

Next, we need to place this weapon in the player’s left hand. Go back to the WeaponManager

component (by selecting Player in Hierarchy again) and click the little circle to the right of the Left

Hand Weapon field in Inspector. Double-click the Left Hand Weapon object we just created.

Your WeaponManager should now resemble the following with both weapons equipped.

Go into play mode and you should now see both weapons equipped like the below screenshot.

Daggerfall Tools for Unity Tutorial Dungeon Basics V1.3.31 [Unity 5.0.1] | 06/08/2015

Devblog dfworkshop.net Forums forums.dfworkshop.net Source github.com/Interkarma/daggerfall-unity YouTube youtube.com/daggerfallworkshop Twitter twitter.com/gav_clayton Email [email protected]

Above: Player with two Dwarven daggers equipped.

Player Footsteps

Right now our player just glides around in silence. Frankly it’s kind of creepy. Let’s add some footstep

sounds.

Select your Player object in Hierarchy and add PlayerFootsteps from Scripts/Demo. This will also

add AudioSource and DaggerfallAudioSource components. You can just ignore these and focus on

the PlayerFootsteps component below.

Walk Step Interval is the number of game units your player must travel (while grounded) before the

next footstep sound is played.

Walk Run Internal is the same for when player is sprinting/running. This helps you tune footstep

intervals independently for each state.

Daggerfall Tools for Unity Tutorial Dungeon Basics V1.3.31 [Unity 5.0.1] | 06/08/2015

Devblog dfworkshop.net Forums forums.dfworkshop.net Source github.com/Interkarma/daggerfall-unity YouTube youtube.com/daggerfallworkshop Twitter twitter.com/gav_clayton Email [email protected]

Pitch Variance is a random +/- pitch applied to each footstep. This prevents footsteps from sounding

too mechanical. Internally, the script creates its own AudioSource for playing footsteps so that other

audio on the player is not modulated by footstep pitch.

Ground Distance is the height above ground where footsteps stop playing. This needs to be a little

higher than expected due to brief moments of controller freefall going down stairs and ramps.

Setting this value too low will result in footsteps falling silent on stairs, and setting this too high will

result in footstep sounds while jumping. The default setting should be adequate in most cases.

Footstep Volume Scale controls the volume of footstep sounds relative to main volume. This is set

to 0.7, which means footsteps are played at just below three-quarter volume.

Footstep Sound is a sound enumeration for the sound played each footstep. There are sounds for

when the player is on a variety of surfaces.

Fall Hard Sound is a sound enumeration played when the player falls from a high distance, but not

high enough to be hurt.

Fall Damage Sound is a sound enumeration played when the player falls from high enough to be

hurt.

If you go into play mode again now, your player should make footstep sounds while walking,

running, and falling from high places.

Action Doors

An action door is a mobile 3D door which can swing open with a hinged rotation. These doors are

different to static doors, which are just painted on the outside of buildings and dungeon exits.

If you drill down into the scene via Hierarchy you will find many action doors added per block. These

were all setup for you by the importer.

Locate the first door leading out of the starting tunnel and select it directly in your scene view, as in

the below screenshot.

Daggerfall Tools for Unity Tutorial Dungeon Basics V1.3.31 [Unity 5.0.1] | 06/08/2015

Devblog dfworkshop.net Forums forums.dfworkshop.net Source github.com/Interkarma/daggerfall-unity YouTube youtube.com/daggerfallworkshop Twitter twitter.com/gav_clayton Email [email protected]

Above: Action door leading out of starting tunnel selected in scene view.

While looking at the Inspector, you will see the door is already setup with a mesh, materials, collider,

audio source, and a DaggerfallActionDoor script like below.

Start Open will start a door in the open position when scene is played.

Is Locked will prevent the player or enemies opening the door, but the player can bash the door

open by attacking it with their weapons.

Daggerfall Tools for Unity Tutorial Dungeon Basics V1.3.31 [Unity 5.0.1] | 06/08/2015

Devblog dfworkshop.net Forums forums.dfworkshop.net Source github.com/Interkarma/daggerfall-unity YouTube youtube.com/daggerfallworkshop Twitter twitter.com/gav_clayton Email [email protected]

Is Magically Held is another form of lock which cannot be bashed open. Only a magic spell (which

would clear this flag) can unlock this door.

Open Angle is the Y rotation used when the door swings open. All action doors are -90 by default.

Open Duration is the length of times in seconds for the door to transition between open and close

states.

Disable Collider When Open changes the collider to a basic trigger when door is opened. This allows

player to walk through the mesh once door has been opened, but is still able to close it again.

Chance To Bash is the base chance of a successful bash per hit. This could be modified by any

number of player statistics, skills, weapon weight and type, etc.

Play Sounds will play the default door sounds.

Open Sound, Close Sound, Bash Sound are the sounds played when the player open, closes, or

attacks the door.

Locked Sound is the sound played when the player attempts to open a locked or magically held

door. It gives the player some feedback the door needs special handling to open.

As an exercise, let’s lock the first door so the player must bash it open to escape the starting tunnel.

With the first door selected, tick the Is Locked property in Inspector like below.

Once the door is locked, enter play mode and try bashing the door open. You should crack it open

within a few swings.

Ambient Sounds

No Daggerfall dungeon is complete without some creepy sound effects and brooding music. Let’s

start with ambient sounds.

Daggerfall Tools for Unity Tutorial Dungeon Basics V1.3.31 [Unity 5.0.1] | 06/08/2015

Devblog dfworkshop.net Forums forums.dfworkshop.net Source github.com/Interkarma/daggerfall-unity YouTube youtube.com/daggerfallworkshop Twitter twitter.com/gav_clayton Email [email protected]

Click menu Game Object > Create Empty. Rename new object to Ambient Effects Player. The

ambient effects use 2D sound, so we don’t need to worry about player position in the world.

With Ambient Effects Player object selected in Hierarchy, add the component Scripts >

DaggerfallWorkshop.Demo > Ambient Effects Player in Inspector. This will automatically setup any

other required components.

Min Wait Time is the minimum number of random seconds before next sound effect plays.

Max Wait Time is the maximum number of random seconds before next sound effect plays.

Presets are available ambient effect presets. More will be added over time, or you can open the

script and create your own custom presets.

Play Lightning Effect is only valid outdoors. It will flash the sky during storms in time with lightning

flashes. Note: This option has been deprecated in 1.3.

Sky For Lightning is the sky to flash. Leave this blank. Note: This option has been deprecated in 1.3.

Light For Lightning is a light to flash brightly when lightning strikes. Leave this blank. Note: This

option has been deprecated in 1.3.

All we need to do here is drop down Presets and select the Dungeon preset. Save your scene and

play the game to hear creepy dungeon sounds like doors opening, moans, scuttling, and chains

jingling.

If you want to hear effects more frequently, play with the min/max wait time until happy.

Adding Music

Now we need some music. Select Player in Hierarchy then click menu GameObject > Create Empty

Child. Rename it to Song Player. This object is parented to player so music will travel with player.

Ensure Song Player transform is positioned at 0, 0, 0.

Now Select Song Player and use Inspector to add component Scripts > DaggerfallWorkshop >

Daggerfall Song Player.

Daggerfall Tools for Unity Tutorial Dungeon Basics V1.3.31 [Unity 5.0.1] | 06/08/2015

Devblog dfworkshop.net Forums forums.dfworkshop.net Source github.com/Interkarma/daggerfall-unity YouTube youtube.com/daggerfallworkshop Twitter twitter.com/gav_clayton Email [email protected]

Show Debug String will show information about the current song. Enable this if you like.

Gain will boost the volume of the playing song.

Sound Bank is the SoundFont used by MIDI synthesizer. Advanced users can import their own

SoundFonts to change how the music sounds.

Song Folder is where the .mid songs are located in Resources.

Song is the current song. This will be played at startup.

Now select track Song_dungeon from the Song list. When you next play the game, our song will start

playing automatically if AudioSource > PlayOnAwake is true. If you would like the music to loop,

make sure AudioSource > Loop is enabled.

If you feel the music is too loud, adjust the Gain until happy.

Note: If music does not start playing, try saving your scene then closing and reopening Unity. There is

an intermittent problem with MIDI synth and Unity editor.

Player Torch

The last thing we need to do is give the player a torch to light their way. The Player prefab already

has a basic torch light included but it is currently disabled. To enable this, expand the Player object

in Hierarchy and select Torch. In the Inspector, click the box to enable the Torch game object.

The next time you play the game, your player will carry with them a simple point light to make their

immediate area brighter. If you would like more light, increase the Range of your Torch object.

Daggerfall Tools for Unity Tutorial Dungeon Basics V1.3.31 [Unity 5.0.1] | 06/08/2015

Devblog dfworkshop.net Forums forums.dfworkshop.net Source github.com/Interkarma/daggerfall-unity YouTube youtube.com/daggerfallworkshop Twitter twitter.com/gav_clayton Email [email protected]

Conclusion

This concludes the Dungeon Basics tutorial. Have fun exploring your dungeon! If you feel up to it,

here are a few enhancements you can make to learn more from the example scripts.

Create a player health system. The player should receive damage from enemy hits and

falling too far.

Handle player death by setting them back to the starting point with full health.

Create a basic stats system for both player and enemies which modify attack speeds and

damage.

Create a simple spell to unlock and open magically held doors. Tip: You can open or close

action doors from script using actionDoor.ToggleDoor().

Create a basic inventory system where the player can change weapons while playing. Tip:

You can change the properties of FPSWeapon from script at runtime to modify weapon and

material type.