- Home /
Top-Down Jumping (2D)
I'm making a top down 2d game, and am struggling with adding a jump to my character.
I want the character to be able to jump over holes and low obstacles (but not high ones).
Essentially something akin to jumping in 2D Zelda titles.
Currently my game is setup to use XY, with gravity turned off (set to 0). Movement is based on simple Rigidbody addforce mechanics.
Any examples, or resources that could help me with this endeavor would be highly appreciated. C# is preferred, but UnityScript is acceptable.
Thank you for your time.
Answer by SethJH · Dec 26, 2013 at 08:11 PM
The best I could come up with would be: Assign some property denoting "hole" tiles to be recognized different from "floor" and "wall" tiles. Normally, while your character is not "jumping", when they come in contact with the hole tile they fall down it and die, or just act as a solid tile (your preference). When the player presses the jump key, set "jumping" to true and the character will "ignore" tiles tagged as holes, allowing them to move safely over it. The jump boolean would return to false after the player has traveled a certain number of tiles (2 is probably what you're looking for). The jump command should require you set a direction to jump (like LEFT ARROW + JUMP), and not allow the player to change directions again until they have landed. To simplify how long the jump should last, you may even replace the boolean Jump variable with a float Jump variable that is set to a number on jump and then decrements at a fixed rate until it reaches 0 again. (then you could have a property bool IsJumping { get { return Jump > 0; } } to check if the player is in midair). The Jump variable as a float would also give you a means of judging which frame of jumping animation to display.
Thank you. I'll try this out shortly. I also think I may be able to work it into combat mechanics (jump over projectiles and such) with a simple check during collison.
I am doing the same thing and posted a question on giving the illusion of jumping from a top down, by scaling the sprite up and back down. The code originally was done in XNA but the concept is the same. http://stackoverflow.com/questions/20309661/scale-sprite-up-and-down-to-give-illusion-of-a-jump I'm in the process of converting it over to Unity.
Your answer
![](https://koobas.hobune.stream/wayback/20220613124903im_/https://answers.unity.com/themes/thub/images/avi.jpg)