For these EEP hours, I will work on the task of making a 2D platformer. I have done a bit on this before so I aim to make it a bit more complex than before. For the movement, I want to have the player able to walk and jump around with some features that make it more polished.
After looking into it a big common theme that games include to make their game more polished is adding a few extra features to the jump. One is the ability to jump just a bit after going off the edge and the second is the ability to jump a tiny bit before the ground.
This will require a timer to keep track of the point where the player should be able to jump.
First, I made a map that could test all the features of the mechanics. for this, I needed two ledges to show jump heights and two gaps to show the jump parameters.
Next, I coded the movement. The movement is simple first I create the floats for the movement speed and horizontal input. As this is a side scroller the movement only has to the side to side movement. I then in the update set the horizontal float to the input of the horizontal axis.
For the movement, I set the velocity to a new vector two using the horizontal times the movement speed.
Here, is the movement before I add the jump code.
For the jumping, the update function holds the main input part of the jump. First, we check if we are grounded, if the player is I set the ground trimer to the timer intervals, if not I count down the timer. Next, if the jump buttons are pressed, I set the jump timer to the timer intervals if not I count down again. These check whether the player is in the right position to jump.
Next, if the above things are true I set the jump to true and set the timers to 0 again allowing us to jump. I also check if the jump is at a low speed and height then use a different low jump.
Lastly, I handle the actual movement of the jump in the fixed update. First, the velocity and the input. If the velocity is less than zero I set the velocity to a new vector using the fall multiplier to handle the up gravity. If it is greater and the player is not jumping it sets the velocity this time using a low jump multiplier.
Then if the jump is used, I set the velocity to the jump force on the y. If it is the low jump, I set the velocity to the regular velocity on the y times 0.5f
A demonstration of the jump using its features of light forgiveness over ledges and a jump that can happen before the ground. As you can see I can not reach the ledge by jumping off the floor but the player can still reach as I jump off the air a slight bit.
Overall I am happy with the feeling of the new and improved platform controller. The controller is nice and forgiving making it feel really nice to play.