Adding a Double Jump Feature to Your Game
Double jumping is a fun mechanic to add to your game. It gives extra maneuverability and can make moving around your game world more exciting. So how do you go about adding this feature? In my last article, I explained how to create a physics-based character controller. I will be adding the ability to double jump to this controller.
The first thing to do when implementing any feature is to think about how it will work. In the case of double jumping, you will want to check if the player is on the ground. If they are not you will want to check to make sure they have not already double jumped. If they are not on the ground and have not double jumped then you want to allow them to double jump.
The first step to creating the double jump feature is to create a boolean variable to check if the player has double jumped yet.
I am going to explain this in a little bit of a reverse way because it will make more sense this way.
After the player has jumped the first time you will check for the input to jump again. You will also be checking for the boolean variable that holds if the player has already double jumped. If the input is detected and the boolean variable is false meaning the player has not double jumped already you will allow the player to double jump.
To allow the double jump add the jump height variable to the current y value of the player. You will also set the boolean variable to equal true which will stop the player from jumping again.
When you have confirmed that the player has hit the ground you will want to set the boolean variable to false to allow the player to be able to double jump again.
You should now have a functional double jump feature.