top of page

Prototype Assignment: Basic sounds, gravity and death by falling

Another member of the team, who has a background in sound, took on the task of sourcing and editing some audio for us to use in this project. He recently delivered a collection of clips to be used for the character's movement and shooting noises. I implemented this audio into the game by adding Audio Source components to the player character and the projectiles they fire and then adding some new code to their respective scripts to trigger the audio. The easier of the two to put together was the projectile audio. I started by adding a AudioSource variable to reference the Audio Source component, and a list<AudioClip> variable which I populated with the 4 different projectile sound clips. I then added a couple of lines in the start function which set the AudioSource variable to refer to the Audio Source component and then play one of the clips in the list at random.

Adding audio for the player character's movement was a little more complex. I started by adding the following variables:







I then added code to the update function to start the playWalkSound function if the player is moving on the ground and the walk sound is not already playing .










The playWalkSound function sets walkSoundPlaying to true so that it doesnt get called again by the update function. It then picks a random clip from our list of walk sounds and plays it. There is then a short delay before the function checks if the player is still "walking". If they are, then the function plays again, if not, then the loop stops and walkSoundPlaying is set to false so that the function can be called again the next time the player walks.












After the audio was done, I added a quick health system, and death function which restarts the level when the player hits 0 health. I also added a kill box below the map which deals lethal damage to the character if they fall off the map and collide with it.












I also made some more changes related to the character's movement. We decided the level was too small for such a mobile character and so simply scaled it up to make more room to dash around. I wanted the player to fall faster, to make them feel weightier. I tried just increasing the mass of the character's rigid body component but that slowed them down and weakened their jump greatly without actually giving them that much more fall speed. To get around this, I turned off the gravity simulation built in to the rigid body and removed the character's mass. I then added my own simple gravity simulation which accelerates the player downwards whenever they are airborne. This allows me to increase the character's fall speed without affecting their run speed. This increased fall speed was easily compensated for by increasing the jump and dash force a little. I originally put this code into the update function, but as this is called on every engine tick, the force of the gravity increased with the game's performance, so those with more powerful PCs would fall faster. This was absolutely unacceptable, so I instead moved the gravity code over to the fixed update function to give it a consistent tick-rate regardless of the game's performance. Removing the character's mass and gravity simulation from the rigid body also removed the simulated drag, meaning that they would slide along even without X axis input. To resolve this I added a simple check which sets the X velocity to 0 if the character is grounded and there is no X input. This had the added bonus of allowing the character to stop moving instantly, making them feel more responsive.


Here's a video showing off all the changes talked about in this post:


Komentáře


bottom of page