- Home /
Jump 2D error
Hi, i am making a 2D game, like "Super Mario", a platform game.
I have a terrain composed by differt parts, that are placed side by side (each part has its own edge collider 2D).
The character jumps if i press the UP arrow. Sometimes the character does a very big jump. This happens when the character jumps very near an object...
What can i do to solve this problem ?
Here you can download the demo of the game for testing and see what is the problem :)
https://www.dropbox.com/sh/x8ff4ajzg70h2k2/AAA03gDiLqd7ZXNBrnLt2L87a
Thank you so much :)
if(jump){
anim.SetTrigger("Jump");
rigidbody2D.AddForce(new Vector2(0f, jumpForce));
jump = false;
anim.SetBool("Ground",false);
}
jumpForce is public variable, so i can chose it, now it is setted as 400
Answer by MrAkroMenToS · Jul 12, 2014 at 12:36 PM
The problem is, as I could saw if you jump next to an object you jump into the sky. I think this is because the addforce activates even if you are jumping.
I'd try to add a criteria.
Try this:
if(rigidbody2D.velocity.y == 0){
rigidbody2D.AddForce(new Vector2(0f, jumpForce));
}
Because i use velocity also for walking and move the character
I see! Is the horizontal velocity the y or the vertical? If y is your horizontal change y to x in my code. If y is the vertical then change to this: if($$anonymous$$athf.Abs(rigidbody2D.velocity.y) <= 1) Play with the 1 number if it doesn't work! I hope it helped.
Your answer
Follow this Question
Related Questions
Make a 2D jump? 0 Answers
Moving platform player bounce when moving down 1 Answer
How can you make an object jump fluid while the object is rolling (2D) 0 Answers
Character clips into the ground in 2D platformer 0 Answers
Velocity in Unity2D 2 Answers