Test Environment
In order to test new and existing mechanics I created a Test Level that would encompass various level design elements in the actual game.
playerParachute
Parachuting is one of the main movement mechanics as stated in the first post, in our case Parachuting slows the players Linear Drag and prevents fall damage.
The Setup
I created a simple vector that is 1.5 the size of the player (to keep it consistent) and created a polygon collider to encompass the parachute itself. Above is the setup in unity, note that the parachute sprite is transparent – this its default state as the parachute only shows when being used.
The Code
Above was the initial script on how the mechanics work, I created new booleans for the power-ups (HasParachute) and integrated the grounded boolean from the playerScript.
Basically, the player’s linear drag is increased if the player pushes and holds the “Jump” button down and is reduced to the default 0 when the button is let go.
Basically, the player’s linear drag is increased if the player pushes and holds the “Jump” button down and is reduced to the default 0 when the button is let go.
A problem that existed was: “What happens if the parachute itself collides with a platform?”, in response I made it so if the player’s parachute hits something it will cancel the parachute effect and make the player fall normally.
I refactored the existing code and added new functions for deploying and cancelling the parachute so the collision function ‘OnTriggerEnter2D’ would just call the same function as holding the “Jump” button – this made the code much neater and prevented repeating code.
Video
Here’s a video of the Parachuting Mechanics. This video is also edited so hopefully it’s clearer to understand!