Hi, does someone know why my player jumps at different heights every time? script: https://paste.myst.rs/xzlk63kh
a powerful website for storing and sharing text and code snippets. completely free and open source.
1 messages · Page 1 of 1 (latest)
Hi, does someone know why my player jumps at different heights every time? script: https://paste.myst.rs/xzlk63kh
a powerful website for storing and sharing text and code snippets. completely free and open source.
UPDATE: this problem only happen if there is Input.GetButton("Jump"). With Input.GetButtonDown("Jump") this problem doesn't occur
I would read the difference between the two
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
let them figure it out!
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
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
In what way?
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
Do you mean like this?
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
Ah so you are suggesting to put the rb.velocity... in the if statement to allow the player to jump only when the y velocity is equal to 1?
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);
}
With Input.GetButtonDown it does work but i like more if i don't have to always re-press the button to jump
i like to hold the button to jump consecutively
yeah thanks it works, i will try to understand more the rb.velocity
yeah, it's really helpful