Design and development of a videogame with dynamic sound based systems with Unity using Wwise
Abstract
This document presents the use of audio middleware software, in conjuction with Unity game engine, in the design and further implementation of different dynamic audio systems applied in a PC videogame. This sound systems include vertical and horizontal music and ambience with custom made audio assets, and how it implements in a short, highly replayable game. A provisional video showcasing the end result can be seen here: BLINDFOLDED
Full text
Design and development of a videogame with dynamic sound based systems with Unity using Wwise. Antoni Bellver Tirado Final Degree Work Bachelor’s Degree in Video Game Design and Development Universitat Jaume I September 20, 2020 Supervised by: Vicente Cholvi Juan
To Andrea Giménez Vila
Acknowledgments First of all, I would like to thank my Final Degree Work supervisor, Vicente Cholvi, for the complete freedom of subject and method regarding the project theme and development. I also would like to thank Sergio Barrachina Mir and José Vte. Martí Avilés for their inspiring LaTeX template for writing the Final Degree Work report, which I have used as a starting point in writing this report. i
Abstract This document presents the use of audio middleware software, in conjuction with Unity game engine, in the design and further implementation of different dynamic audio systems applied in a PC videogame. This sound systems include vertical and horizontal music and ambience with custom made audio assets, and how it implements in a short, highly replayable game. A provisional video showcasing the end result can be seen here: BLINDFOLDED iii
Contents Contents v 1 Introduction 1 1.1 WorkMotivation................................ 1 1.2 Objectives.................................... 2 1.3 Environment and Initial State . . . . . . . . . . . . . . . . . . . . . . . . . 2 2 Planning and resources evaluation 3 2.1 Originalplanning................................ 3 2.2 Final planning and Resource Evaluation . . . . . . . . . . . . . . . . . . . 3 2.3 WhyWwise................................... 5 3 System Analysis and Design 7 3.1 Blindfolded: Demo Concept . . . . . . . . . . . . . . . . . . . . . . . . . . 7 3.2 Blindfolded: Design Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 3.3 Blindfolded: Core Components . . . . . . . . . . . . . . . . . . . . . . . . 8 3.4 Blindfolded: Core Mechanics . . . . . . . . . . . . . . . . . . . . . . . . . 9 3.5 RequirementAnalysis ............................. 10 3.6 SystemDesign ................................. 14 3.7 SystemArchitecture .............................. 14 3.8 InterfaceDesign................................. 14 4 Work Development and Results 17 4.1 WorkDevelopment............................... 17 4.2 Sound ...................................... 18 4.3 Gameplay.................................... 22 4.4 Assets ...................................... 25 5 Results 29 5.1 GeneralConclusions .............................. 29 5.2 Conclusions:Unity............................... 30 5.3 Conclusions:Wwise .............................. 30 5.4 Conclusions: Audio asset creation . . . . . . . . . . . . . . . . . . . . . . . 30 5.5 Futurework................................... 30 v
6 Planning and resources evaluation Figure 2.2: Gantt chart of this project development).
Chapter 3 System Analysis and Design Contents 3.1 Blindfolded: Demo Concept . . . . . . . . . . . . . . . . . . . . . . . 7 3.2 Blindfolded: Design Goals . . . . . . . . . . . . . . . . . . . . . . . . 8 3.3 Blindfolded: Core Components . . . . . . . . . . . . . . . . . . . . . . 8 3.4 Blindfolded: Core Mechanics . . . . . . . . . . . . . . . . . . . . . . . 9 3.5 RequirementAnalysis........................... 10 3.6 SystemDesign............................... 14 3.7 SystemArchitecture............................ 14 3.8 InterfaceDesign .............................. 14 3.1 Blindfolded: Demo Concept The playable demo to test all implemented audio systems is called Blindfolded. Blindfolded is an oppressive adventure game with a gameplay timespan no longer than 5 minutes. In it, the player will control a blindfolded, handcuffed individual trying to escape it’s captors as he runs through a small terrain parcel. With only a few visual hints in the middle of a pitch black screen, sound will be the only possible guidance to safety, as footsteps, noises, heavy breathing and music dynamically build up tension to unbearable amounts. It will make use of a top-down perspective, and it’s controls will be minimal, only using computer’s mouse and a reduced set of keys. 7
8 System Analysis and Design Figure 3.1: 3.2 Blindfolded: Design Goals Blindfolded aims to create a short but rather intense gameplay experience. With its simple controls, minimal (more like non-existent) UI and small map size, the experience focuses on the overwhelming sensation of being restrained and deprived of vision, the most valuable of all five senses, in a hostile environment where auditory stimuli will become as stressful as necessary to escape successfully. The use of headphones becomes rather mandatory. 3.3 Blindfolded: Core Components Any of them have a concrete physical appearance due to the fact that everything is obscured. The only visual clue for representing them will be the footprint they leave as they travel through the map, or a flare effect piercing through your blindfold as they approach in the case of cars. 3.3.1 Player character A regular, anonymous person trying to escape from its captors. It could be you.You’ll continuously hear your own footsteps. As you play and run away from the NPC’s, you will be able to hear and perceive how your breathing gets more intense. The only visual clue you get of yourself is an stylized version of your footprints, in a white color. 3.3.2 Persecutor These NPC’s will be searching for the player. The player will be able to hear them walking if the gets close enough and, if he’s been moving silently enough, he’ll be able to walk around them with no trouble. If he gets spotted, they’ll run towards him. The player is always faster than the persecutors, so running away from them may save you, but take into account that your breathing and stepping sound will be louder, alerting
3.4. Blindfolded: Core Mechanics 9 more of them in the process. It they get to you, is game over. The only visual clue representing persecutors are their footsteps, in a red color. 3.3.3 Cars A both-ways road traverses the scenario. It depends on the procedural randomness of each level, but most of the time the player will have to cross it to scape. Cars continuously pass at outrageous speed. The sound of the engine plus the wind being pulled by the car’s force will be the best clue for the player to try to dodge them as he crosses the road. Their visual representation is a flare effect from their front lenses, piercing through your blindfold as they approach. They won’t see the player coming, so if he stays too much time in the middle of a road he might get hit, with an instant game over as a consequence. 3.3.4 Level Trees and bushes will fill the area. They are harmless and just obstruct the player’s movement as he blindly explores the scenario. They can be quite annoying if the player is just trying to run through the level, as he can just crash into them, getting knocked down for a couple of seconds, or getting stuck into them (in the case of bushes). There are two-ways roads are filled with cars, that will continuously run through them. They won’t see the player coming, so if he stays too much time in the middle of a road he might get hit, with an instant game over as a consequence. They are plotted in any given direction, dividing the level. Scaping is not easy, as big part of the level is surrounded by an electrified fence. If the player walks near it, he can hear the static noise and follow it, looking for a gate or overture to overcome it. Crashing into it will stun the player for a good amount of time, and it will generate a good amount of noise that might alert persecutors that walk nearby. All these items, scattered trough the demo, create certain particle systems when the player crashes on them. 3.4 Blindfolded: Core Mechanics 3.4.1 Movement Your footprints and footsteps will occur continuously in the direction you are moving.You can choose to walk, resulting in advancing at a slower pace, but the quieter your breathing and overall stealth will be. You can also run, being able to escape most persecutors, but increasing the danger of crashing into fences or trees. 3.4.2 Sound High pitch strings howl as persecutors run at the player. The electrified sound of fences. Car engines rushing through the road at 120Km/h in front of you. The sound itself is
10 System Analysis and Design the core mechanic in Blindfolded. With no vision, the player has to rely on everything he hears to locate himself in the space he is moving. A rich and deep soundscape brings the immersion and main feature of Blindfolded. 3.5 Requirement Analysis To carry out a job, requirements where divided into three different categories: one regarding everything that has to do with Unity (game engine), another one for all the tasks needed to implement in Wwise(sound engine), and one last category for everything regarding to asset generation. 3.5.1 Functional Requirements There is a handful amount of requirements that needed a proper implementation, both for Unity and Wwise, in order to make the demo possible. These include from scripts for player and npc’s to dynamic music systems and spatial audio systems for most of the entities present. A complete list can be found in this section. Input: (UNITY) Player Movement Script Output: Player can move ingame The player entity in the engine may need an script which allows it to move using W,A,S,D keys and rotate camera around itself, as well as choose whether to walk or run pressing the "L SHIFT" key. Table 3.1: Functional requirement «CRED1. Player Movement» Input: (UNITY) Collision Manager Script Output: Game knows what has the player collisions with. The game has to properly process the different type of collisions that can happen. If the player collisions with a persecutor or car, the game ends. If the player collisions against a tree or fence, instead, it will get the proper stun penalty depending on it’s current speed in the moment of the collision. Running blindly in the woods by night is not a good idea. Table 3.2: Functional requirement «CRED2.Collision manager» 3.5.2 Non-functional Requirements As non-functional requirements, there is a game design document explaining most of the design decisions and concepts, that can be found with the demo. It also includes a PDF
3.5. Requirement Analysis 11 Input: (UNITY) Game Over Script Output: Game knows when it’s game over, and proceeds to end the demo. When player collisions with a persecutor or gets stomped by a car, a message that "YOU DIED" will fill the screen. When player successfully escapes the level, a "YOU ESCAPED" message fills the screen. Table 3.3: Functional requirement «CRED3. Game Over Manager» Input: (UNITY) Visual Clues Output: Most of the things that can happen have some kind of minimal screen representation. From footsteps to car flashes, most of the things that can be heard can be visually perceived as abstract clues on the screen, spatially positioned near to where the sound happened. Table 3.4: Functional requirement «CRED3. Visual Clues» Input: (UNITY) Persecutors AI Output: State machine and behaviours for enemy NPC’s. Persecutor NPC’s are able to follow pseudo-randomized patrol routes, leave them when they hear noise to chase the player, and return to them if they loose track of their target. Cars will follow roads, entering and exiting the level continuously. Table 3.5: Functional requirement «CRED4. AI» Input: (UNITY) Level Design Output: Combining all the assets and creating an interesting demo. The objective is to create a interesting, highly replayable showcase demo using all of the implemented systems. Thanks to the randomized enemy patrols and gameplay mechanics (complete darkness) the player can attempt multiple runs with very different results. Table 3.6: Functional requirement «CRED5. Level Design»
12 System Analysis and Design Input: (UNITY) Graphic and balance adjustments Output: Polishing the game experience. Applying culling, as well as some graphic effects like grain or distortion to create a more gritty look and a more intense experience. This minor changes won’t affect gameplay but will help to create a better cohesion with the sound aspect of the project, which is it’s main focus. Table 3.7: Functional requirement «CRED6. Adjustments» Input: (WWISE) Character footsteps sound Output: Characters generate spatially correct placed footsteps sound. It is important to create footsteps for both player and NPC’s. These have to be different in feel and dynamic, to make clear which ones are being generated by the player and which are being generated by persecutors, as well as being placed in the game space correctly as they sound. Table 3.8: Functional requirement «CRED7. Footsteps audio» Input: (WWISE) Character breathing Output: Player character variable breathing intensity and feel depending the situation. As player character gets more and more nervous (and tired), his or her breathing will increase in intensisty. This can happen because of some factors: being persecuted and enemy NPC’s get near, stepping on some obstacle, sprinting for too long... Table 3.9: Functional requirement «CRED8. Breath audio» Input: (WWISE) Dynamic ambience Output: Game world has it’s own dynamic, organic soundscape A mix of forest sounds, static noise and synthesizers changing in pitch and dynamic create the game main soundscape. All this audio stems can vary in volume, stereo placement and signal processing depending the situation of the player. Table 3.10: Functional requirement «CRED9. Ambience audio.»
3.5. Requirement Analysis 13 Input: (WWISE) Tension and game over audio effects Output: Perfectly transitioned and balanced audio effects to add tension and end the game. Every time an NPC hears the player and starts following it, an audio effect transition will occur on top on the dynamic ambience. High pitched strings and distorted sounds will push the player and urge him to run. Table 3.11: Functional requirement «CRED10. Effects» Input: (WWISE) Car sound effects Output: Spatial wind-breaking car effects from the vehicles travelling the road at high speed. As player comes close to the road, a new audio system gets involved: car sounds. Being completely blind and trying to cross the street should look and feel like a completely scary situation, and this sound will help create that feeling. Table 3.12: Functional requirement «CRED11. Car audio» Input: (ASSETS) Character footsteps sound and look Output: Footsteps particle system As the player moves, the most important visual clue it will get is where he or she is stepping on. Stylized footsteps will appear onscreen, synchronized with audio systems as footsteps sound. Table 3.13: Functional requirement «CRED12. Footstep Design» Input: (ASSETS) Create dynamic ambience soundscape. Output: Audio stems for ambience soundscape. To create the loop stems that are used in game (and before putting them trough Wwise), a mix of sample based recordings of forest noises and some basic sound synthesis for digital strings will be. Table 3.14: Functional requirement «CRED13. Ambience Design»
14 System Analysis and Design Input: (ASSETS) Create a believable breathing progression. Output: A set of audio stems that represent an increasing intensity breathing For this purpose, and because all libraries with such materials are out of budget for this project, recording myself to create the stems is the best option. The hardware specifications for recording are specified in 1.3 Table 3.15: Functional requirement «CRED15. Breathing Design» Input: (ASSETS) Create good coherent tension effects for audio detail. Output: A handful of audio effects used ingame for key moments. Using some basic sound design and royalty free samples, create unique and gritty sound effects for all events happening ingame. Table 3.16: Functional requirement «CRED16. Effect Design» that serves as a manual for the playable game, with its keyboard controls and a little survival guide. 3.6 System Design (see Figure 3.2) 3.7 System Architecture The demo does not require big computation regarding polygons or complicated calculations, so I find counter-intuitive to set system requirements to play the game. Any home machine may be able to run it with no problems. 3.8 Interface Design As for its main menu, Blindfolded features a minimal main menu,where the game title floats in the middle of the screen, just accompanied by a big "ESCAPE" lettering. Pressing on this one and only option will start a run. Options to disable sound are not implemented, as this decision will severely impact gameplay experience (making the game impossible to play). In game, there is no UI of any kind. All the information the player needs is transmitted via the different visual clues in the screen or, most importantly, the sound design. Stamina and health state are represented by how heavy your breathing and footsteps
3.8. Interface Design 15 Figure 3.2: The demo game flow is very straightforward. are, the type of terrain you are walking on can be identified by the sound of your footsteps, and so on. The only text the player will get on screen are two big announcements: rather "YOU ESCAPED" or "YOU DIED" at the end of each run.
22 Work Development and Results 4.3 Gameplay 4.3.1 Player character: Controls Blindfolded controls follow the classic, archetypal control design philosophy behind every modern action game played on a keyboard; where left hand covers movement and functionalities linked to keys while right hand is used for mouse movement and clicks (see Figure 4.4). 4.3.2 Non playable characters: AI To create enemy behaviour, a finite state machine has been implemented, allowing to create a set of different states and how they are linked in order to make them capable of adapting to multiple situations and creating a challenging, better experience. In any moment where the player is far away from persecutors, they stay patrolling, reaching a set of in game space points in a sequential order. This points are scattered trough the level, and are assigned manually to each patrol. As the player gets near them, the compare the noise the player character is generating in that exact moment (waling or running, intense breathing ,etc) and start chasing it if they heard something. If the player gets far enough, or if persecutors stop hearing noises for a short period of time, they’ll get back on their patrolling routine. For balance purposes, persecutors are as "blind" as the player (see Figure 4.5). 4.3.3 Resources To keep track of the current state of the player, there is a set of stats that, although are not shown to the player in any moment, define how the character is doing. When playing the game, all this information gets to the player trough the different audio systems. •Stamina is represented by an integer that can go up to 100. Each second, a number of stamina is regained if the player is not running, in which case will decrease a certain amount. This stamina value is directly linked to the dynamic breathing RTPC, making it possible to have the player character breathe heavily and continuously as his stamina is about to deplete, and sounding completely calmed again when he has walked for a while. •Danger is also measured with an integer. In this case, this integer starts at 0, and can go up the more enemies are near you, how close they are to the player or if they are aware of your presence and by so, persecuting you. The same way as stamina, the value of danger is linked to the RTPC controlling the dynamic ambience, making it possible to quickly set an obnoxious atmosphere of drones and string when then player is being chased by multiple enemies, and come back to just the calmed wind and some noises if he manages to scape.
4.3. Gameplay 23 Figure 4.4: PC controls.
24 Work Development and Results Figure 4.5: NPC behaviour flow.
4.4. Assets 25 •Footstep noise is represented by a collision box surrounding the player. This box gets bigger as the player is more noisy (running, breathing etc), and, it collides with the detection range of any enemy, it will start a persecution. 4.4 Assets Most of the assets used in the demo are handmade. To create everything sound related, Ableton Live 9, a digital audio workstation, was used. This kind of software lets producers create, mix and arrange audio signals in a complete digital work space.The assets created this way were then exported and set into Wwise with already adequate volume levels, dynamic range and tonal balance. To put it simply, they were imported into the audio engine already processed and mixed to sound good, leaving only the scripting and organization part to be taken care of. 4.4.1 Environmental sound The environmental sound in Blindfolded conforms the dynamic ambience, consisting of: •White noise, created using an oscillator, then exported to a stem and loaded into Wwise. It fills the ambience with random frequencies, creating a chaotic feeling. •Drone sound, playing a basic pitch shifted harmony, synthesized and then exported to audio, then loaded intro Wwise. It fills big part of the low end of the audio spectrum, creating the tension and unsettling feeling. •Dissonant strings, coming from a sample of already recorded strings with a free license. They server as the top, most discordant and gritty part of the ambience. (see Figure 4.6) 4.4.2 Breathing Four different tracks of breathing were recorded and processed, then loaded into Wwise. They increase in intensity and weight, going from a pleasant, slow breath to an exhausting heavy breathing. As most of this assets are usually recorded in professional, an-echoic rooms in high end studios, the recorded signal had to go trough a gate, making sure everything below certain volume threshold was not recorded, so no background noise or extra room tone was inside the signal. The tracks were then compressed and equalized properly, so they would sit nicely in front of the ambience, as they are the nearest audio source during gameplay. 4.4.3 Visual clues and effects All of the visual clues and effects used in the demo are built using Unity’s particle system tool. Sprites used in this implementations where created in Photoshop, following
26 Work Development and Results Figure 4.6: Different ambience tracks beign processed and arranged in Ableton Live 9 DAW. references like real life items such as footprints or lightning. In the case of footsteps, for example, the particle system will generate one new footprint every time the player advances a little distance. The number of maximum footprints stays the same no matter the speed at which the player is running, making the older ones disappear. If the player stays move less, footprints already generated will start to fade away as time goes by, same happens with NPC’s. In the next figures you can see some of the visual results (see Figure 4.7) (see Figure 4.8) (see Figure 4.9).
4.4. Assets 27 Figure 4.7: Footsteps generation "behind the curtain". Figure 4.8: Footprint PS.
28 Work Development and Results Figure 4.9: Car tracks "behind the curtain".
Chapter 5 Results Contents 5.1 GeneralConclusions............................ 29 5.2 Conclusions:Unity ............................ 30 5.3 Conclusions:Wwise............................ 30 5.4 Conclusions: Audio asset creation . . . . . . . . . . . . . . . . . . . . 30 5.5 Futurework ................................ 30 5.1 General Conclusions As a musician and producer that moves mainly (only) on the digital world, I found this experience, more than anything, very enriching and complementary. Videogame studios search for very specialized individuals, as videogame development requires a higher level of segmented knowledge. Learning to use Wwise and developing this demo served to set the bases in the creation of both vertical and horizontal dynamic audio systems, and combining it with self-made assets created a very centered perspective of the actual work of audio specialized developers in the industry. Even if some of the assets couldn’t meet professional quality standard, as they have been recorded and processed in nothing more than a humble home studio, getting this vision on how much effort and time has to be put in sound implementation has been very revealing, as sound always comes as the "missing brother" in almost any cultural product. 29
30 Results 5.2 Conclusions: Unity Regarding Unity, the demo turned out simple, but effective. It was not the main goal of this project to create a very complex or long experience, but having to take care of every aspect of a little game ended up boosting my Unity knowledge. The demo is a finished experience, highly re playable and stable, but, as specified in the section below, one of the main problems was the lack of time to create a bigger experience with all the initial mechanics implemented. Some of the extra features for Blindfolded, such as enemy variation and procedural level generation, had to be taken away in order to focus on a more polished and deep audio system. 5.3 Conclusions: Wwise Regarding the audio engine, all the main objectives and expectations were filled. The idea of implementing both vertical and horizontal dynamic audio systems is fulfilled and these are integrated in the demo, completely functional. This included the use of containers, RTPC’s and switches to establish all the internal logic and asset coordination of those systems. This also includes the use of spatial audio tools. These where not considered to be used in the first place, but turned out to enhance the footsteps system a lot. Everything introduced int his demo remains to be tested with a greater quantity of stems, more samples and, in general, a bigger game. The process of learning from zero how audio engines work and how to work with them in conjunction with Unity has been very enriching, and gave a better, more indepth perspective on game making. 5.4 Conclusions: Audio asset creation Asset creation ended up being the most time consuming and complex part of it all. Recording, processing and preparing assets to be used directly into development was a long process plenty of missteps, where a lot of extra hours were spent. Far from the desired professional feeling of the results, it has been very enriching. The lack of proper studio equipment really reduced the quality of this recordings, weakening some aspects of the demo gameplay experience. 5.5 Future work Creating a richer experience in the demo should be the main focus. This could be done by, first of all, adding procedural level generation. Implementing a system that procedurally generates NPC’s, routes for them, as well as places trees, roads and other obstacles should be a great addition to it. Some extra ideas in the first design document were not implemented due to lack of time or other systems having more priority to be done, but adding more types of NPC’s with their own sound set would also help enhance the demo.
5.5. Future work 31 I would also like to point out that some of the assests, specially everything regarding to the main character breathing, could be re-recorded on a Foley room with better acoustic conditions, leading to a more polished breathing intensity system with smoother transitions.
38 Source code 100 foreach (Transform t in enemies) 101 { 102 float dist = Vector3.Distance(t.position, currentPos); 103 if (dist < minDist) 104 { 105 tMin = t; 106 minDist = dist; 107 } 108 } 109 return tMin; 110 } 111 112 private void SetAmbience(float distance) 113 { 114 if (distance < 90f) 115 { 116 ambienceRTPC = (100 - distance) - 10; 117 } 118 119 120 } 121 122 private void SetBreath(float stamina) 123 { 124 breathingRTPC = 100 - currentStamina; 125 } 126 127 void Movement() 128 { 129 float horizontal = Input.GetAxis("Horizontal"); 130 float vertical = Input.GetAxis("Vertical"); 131 132 Vector3 movement = new Vector3(horizontal, 0f, vertical) *Speed *Time.deltaTime; 133 transform.Translate(movement, Space.Self); 134 135 } 136 } Enemy Behaviour Script 1/*Enemy Behaviour */ 2 3using System; 4using UnityEngine; 5using UnityEngine.AI; 6using UnityEngine.SceneManagement; 7 8public class Enemy : MonoBehaviour 9{ 10 public NavMeshAgent agent; 11 public PlayerMovement playerNoise; 12 public Transform objectToChase;
Source code 39 13 public Transform[] waypoints; 14 public int currentWaypoint = 0; 15 16 public enum EnemyStates 17 { 18 Patrolling, 19 Chasing 20 } 21 22 public EnemyStates currentState; 23 24 25 void Update() 26 { 27 float playerDistance = Vector3.Distance(transform.position, objectToChase.position); 28 if (playerDistance > 10f) 29 { 30 agent.speed = 1.5f; 31 currentState = EnemyStates.Patrolling; 32 } 33 34 35 36 if (currentState == EnemyStates.Patrolling) 37 { 38 if (agent.remainingDistance < agent.stoppingDistance) 39 { 40 currentWaypoint++; 41 if (currentWaypoint == waypoints.Length) 42 { 43 currentWaypoint = 0; 44 } 45 } 46 agent.SetDestination(waypoints[currentWaypoint].position); 47 } 48 49 if (currentState == EnemyStates.Chasing) 50 { 51 agent.speed = 4f; 52 agent.SetDestination(objectToChase.position); 53 } 54 55 InNoiseRange(playerDistance); 56 //SetAmbience(playerDistance); 57 58 } 59 60 61 private void InNoiseRange(float distance) 62 { 63 if(distance < playerNoise.noise) 64 { 65 currentState = EnemyStates.Chasing; 66 }
40 Source code 67 68 } 69 } Footseps 1/*Footsteps */ 2 3using UnityEngine; 4using UnityEngine.AI; 5 6public class PlayerFootsteps : MonoBehaviour 7{ 8public ParticleSystem system; 9public Material activeParticleMat; 10 11 Vector3 lastEmit; 12 13 public float delta = 1; 14 public float gap = 0.5f; 15 int dir = 1; 16 static RingbufferFootSteps selectedSystem; 17 18 void Start() 19 { 20 lastEmit = transform.position; 21 } 22 23 public void Update() 24 { 25 26 27 if (Vector3.Distance(lastEmit, transform.position) > delta) 28 { 29 var pos = transform.position + (transform.right *gap *dir); 30 dir *= -1; 31 ParticleSystem.EmitParams ep = new ParticleSystem.EmitParams(); 32 ep.position = pos; 33 ep.rotation = transform.rotation.eulerAngles.y; 34 system.Emit(ep, 1); 35 lastEmit = transform.position; 36 AkSoundEngine.PostEvent("concrete_walk", gameObject); 37 } 38 39 } 40 41 } Collision Management
Source code 41 1/*Collision Management */ 2 3using System.Collections; 4using System.Collections.Generic; 5using UnityEngine; 6 7public class CollisionManager : MonoBehaviour 8{ 9public PlayerMovement playerMovement; 10 11 private void OnCollisionEnter(Collision collision) 12 { 13 if (collision.gameObject.tag == "Tree") 14 { 15 Debug.Log("Choque con arbol"); 16 17 if (playerMovement.Speed >= 3.5) 18 { 19 playerMovement.Speed = 0; 20 playerMovement.currentStamina = 0; 21 } 22 } 23 24 //Chocar con valla 25 26 if (collision.gameObject.tag == "Enemy") 27 { 28 Debug.Log("Choque con enemy. GAME OVER."); 29 AkSoundEngine.SetState("Dead_or_alive", "Dead"); 30 } 31 32 //Chocar con coche 33 34 if (collision.gameObject.tag == "Car") 35 { 36 Debug.Log("Choque con coche. GAME OVER."); 37 } 38 } 39 }