04 / Devlog, Sep 20 '23: player design
GitHub: https://github.com/nebulousmango/The-Body-Metallic
Document references:
- Game design doc: link
The Player Object is an empty parent with a Rigidbody, Capsule Collider and PlayerController script. The Main Camera and the 3D player model are its child objects. The Player Model uses an Animator component.
Player movement
The MovePlayer function uses the player's WASD key inputs to change the player object's velocity and play its movement animations.
The RunPlayer function increases the player's velocity while the left shift key is held down. The player's base speed and running speed can be set in the Unity editor.
The Jump function in the PlayerController script checks for whether the player is in contact with the floor layer and is pressing the spacebar. If both conditions are true, it applies an upward force to the player object. The function also starts a coroutine, which sets off the jump animation and plays a jump sound effect (an audio file of sneakers hitting a wooden floor). The coroutine then waits for one second before letting the player jump again: this is to avoid janky animations and SFX when the jump is spammed.
Movement animation
The Movement layer uses a 2D freeform directional blend tree to play all the running animations. The tree uses nine motion fields covering four cardinal directions (forwards, backwards, left, right) and four ordinal directions (diagonal movements).
Jump is an additive layer in the Player's Animator Controller. It uses a bool to check for whether the player's jumping, and triggers the animation when the bool is true.
Player (and environment) audio
The scene's audio is handled by an empty game object with the AudioManager script. This script uses the public SoundData type, with which I've added three audio files (one for the player jumping and two for the door opening). The PlaySound function here is used by functions in other scripts (for example, the Jump function in the PlayerController script uses it to play a sound effect).
Get The Body Metallic
The Body Metallic
Automaton troubles.
More posts
- 05 / Devlog, Sep 20 '23: enemy designSep 26, 2023
- 03 / Devlog, Sep 20 '23: level designSep 26, 2023
- 02 / ColophonJan 13, 2023
- 01 / Devlog, August 15 '21: bug fixesAug 14, 2021