Player Movement


The current build implements a basic movement system for the player character. Right now this is super simplistic, but will be reiterated as the project continues. 


Controls:

A / D or left arrow / right arrow to move left and right.

W or up arrow to jump.

Hold spacebar in mid-air to parachute, let go of spacebar to release the parachute. 



Gif showing the player jumping and parachuting through the test build obstacle course. (Note: camera zoomed in on gif to reduce file size. Actual game has far more zoomed out camera for a better gameplay experience.)


Testing / Things to Improve:

- Right now the parachute only works if the player jumps first due to the implementation of the code. This means that the player can't parachute if they run off a platform without jumping. Fortunately, this should be fairly simple to fix in code by changing the Boolean parameters that allow the player to use the parachute function. 

- The jumping feels a bit 'floaty' as there is a single fixed jump height and the player character feels slightly too slow when falling back down from the jump peak. I aim to fix this in code by altering the forces applied to the player while jumping to achieve a smooth feeling 'jump curve'. It is also my goal to implement code to allow the player to change their jump height depending on how long they hold the jump button down.


Implementation:

The implementation of the movement was very straight forward. The left and right movement is handled by reading the horizontal direction input of the user, and then setting the velocity of the player to have a horizontal component of a set speed (which can be edited in the Unity inspector) in the direction of the user's input. The vertical component  of the velocity remains unchanged. Implementing the movement like this is very simple and ensures that the player can move left and right whether they are in a running, jumping or parachuting state. An issue I found with this movement implementation was that the player could 'stick' to the side of a wall if they held down the direction key while in mid-air. This was fixed by creating a new 2D physics material with 0 friction and bounciness. The movement controls can be improved by adding an acceleration from zero to max speed when the movement key is pressed down, and decelerating from max speed to zero when the key is let go. This would make the controls feel more smooth, as currently the player instantly goes from zero to max speed when the key is pressed. 

The jumping currently works by reading if the player has pressed the jump button, and then setting the velocity of the player to have a vertical component of a set speed upwards (which can be edited in the Unity inspector). The horizontal velocity remains unchanged. This implementation works well in conjunction with the horizontal movement system .  To prevent the player from infinitely propelling themselves upwards, the functionality of the jump is restricted by using a Boolean parameter. The player can only jump if they are "grounded",   which is calculated by determining if the collider of the player is in contact with another collider labelled "ground" (ie. platforms or cave floor).  This kind of implementation of jumping is very common in platforming games, but it is effective. The jumping function can be improved by changing the jump height depending on how long the player holds the jump button down for. This will take more time to implement and involve much more code, but the result will definitely be worth it. Having responsive and natural feeling controls is a huge priority in this project, and the jumping functionality is one of the most important parts of the controls.

The parachute function itself is very simple: when the player holds down spacebar the vertical component of the player's velocity is set to zero and the gravity scale of the player is set to a low value (that can be edited in the Unity inspector). In the current build this is 0.05, or 5% of normal gravity, which was selected as it feels very natural for the parachuting state without being too slow. When the player stops holding down spacebar, the gravity scale is set back to 1 (ie. normal gravity). Gravity is also set back to 1 if the player lands on the ground, as they could still be holding spacebar down when they land. 

It was also necessary to restrict when the player can parachute by using Boolean parameters. These parameters were 'jumping' (which determines if the player is currently in a jumping state), 'parachuting' (which determines whether the player is already parachuting), and 'mustFall' (which determines if the player has already parachuted before they have landed from their initial jump). When the player lands on the ground all these values are set to false. The player can only use the parachute function when 'jumping' is true, 'parachuting' is false, and 'mustFall' is false. All three of these conditions must be met for the player to parachute. When the player lets go of spacebar after parachuting, 'mustFall' is set to true, meaning that the player cannot parachute again until after they land on the ground. The implementation of the parachute function needs to be altered to allow the player to parachute when they run off a platform without jumping, which should be fairly straightforward to fix. 

The player character was animated using the Animator state machine in Unity. These states include "Standing Still", "Running", "Jumping", "Parachuting" and "Landing". Blend trees were used to animate these states using the float parameter "xSpeed" to determine whether the player is facing left or right. The transitions between the different states were handled using Boolean parameters that were be set in the player movement script. 


Credits:

- Original sprite sheet for the player character was created by GrafxKid on OpenGameArt.org. Has been slightly modified by me. 

GrafxKid.2015.'Classic Hero'.OpenGameArt.org. [Online] Available at: Classic Hero | OpenGameArt.org 

- Cave tile map by Hapiel on OpenGameArt.org.

Hapiel.2014.'Open Pixel Platformer Tiles and Sprites'.OpenGameArt.org. [Online] Available at: https://opengameart.org/content/open-pixel-platformer-tiles-sprites

-Youtube video on 2D platforming movement.

Brackeys. 2018. '2D Movement in Unity (Tutorial)'. Youtube. [Online] Available at: 

- All other assets in this build (altar, spikes, and dancing ghost) created by me. 

Files

Build 2.zip 6.1 MB
Apr 16, 2021

Get Cave Divin'

Leave a comment

Log in with itch.io to leave a comment.