- Home /
How to jump in a 2D world?
I have setup my game in 2D. I have created an isometric view with graphics.
The hero can walk left, right, north and south. I move it using translate.
I wanted the character to jump in those directions too. I was planning to use add force but realized that there is no ground plane.
For example when the character facing north when I press space-bar he should travel (jump) to a position above the current position.
Can anyone suggest how I can make the character jump in those directions?
Answer by moviemastersdk · Dec 10, 2014 at 03:18 PM
Maybe create a float variable called zPos, and then manually add gravity and the jump force to it
if you have another variable called zVel you can set that to maybe 2 when you want to jump, and then on every FixedUpdate() you subtract it by the gravity. but make sure that you limit the Zpos to where the player currently is in the tilemap
void Jump(){
zVel = 2;
}
void FixedUpdate(){
zVel -= 1;
if (zPos > minZPos) {
zPos += zVel;
}
}
this code is not tested, and probably wont work. It is just an example of what i was talking about, and might help you get the idea :)
Your answer
Follow this Question
Related Questions
how to control gravity for addforce ? 1 Answer
AddForce to Camera 1 Answer
[2D] gravity independant jumping 1 Answer
How do I stop an object from jumping VERY high at first? 1 Answer
What's wrong with this script? 4 Answers