#Problems with 2D jump

1 messages · Page 1 of 1 (latest)

rugged galleon
rugged galleon
#

UPDATE: this problem only happen if there is Input.GetButton("Jump"). With Input.GetButtonDown("Jump") this problem doesn't occur

daring ether
#

I would read the difference between the two

mossy thunder
#

Ok, so with Input.GetButton("Jump"), it returns true every time it runs, so if you tapped it, then it might run only once or so, but a slight bit longer, and it adds even more force. Even though you are adding force, for a tiny bit of time, it will still be on the ground

#

try adding a slight delay or something

#

GetButtonDown returns true once, when you press the button down, and only once

daring ether
#

let them figure it out!

rugged galleon
# mossy thunder Ok, so with Input.GetButton("Jump"), it returns true every time it runs, so if y...

Before writing this post i knew that: with Input.GetButton, when you press the button, it will return true while the button is held down so if you hold it then the value will remain true and everytime the player touch the ground it will jump again
automatically. The Input.GetButtonDown instead return true only during the frame when the button was pressed so it will not return true until the user has released the button and pressed it again.

#

I didn't understand why Input.GetButton add a little of force

mossy thunder
#

If you still want the functionality of being able to hit jump too early and still jump as soon as you can check out jump buffering

#

You might also want to use velocity considering you have a rigid body attached

mossy thunder
#

With the command: (variable).velocity = new vector2(1,1); the variable needs to be your rigid body, and the numbers are the direction

#

The vector is an arrow that points somewhere with a speed, and the velocity becomes that with the command

mossy thunder
#

no, because the add force can do it multiple times, but if you did the rb.velocity = new Vector2(1,1); as the only line in that if statement, then it should work, AddForce can be weird too if you try having double jumps or something

#

gravity still is pulling you down when you are on the ground, just you don't see it, try watching what happens to the Y velocity during that clip under info

rugged galleon
mossy thunder
#

no, because the Y velocity keeps going down when you are on the ground

#

so if you set the velocity, then you ignore the previous velocity you had

#

the ground check seems like it works, so don't worry about that

#

what about:
if(Input.GetButtonDown("Jump") && isGrounded))
{
rb.velocity = new Vector2(rb.velocity.x, jumpForce);
}

rugged galleon
#

i like to hold the button to jump consecutively

mossy thunder
#

that's fair, it still should work

#

if you do Input.GetButton

rugged galleon
#

yeah thanks it works, i will try to understand more the rb.velocity

mossy thunder
#

yeah, it's really helpful