Jumping with rigid body velocity doesn't feel good
Hello, I'm using the classic way to make a character jump by changing it's Rigidbody's velocity, code in the next image :
The problem is that sometimes when I hit the ground, I have to wait a few frames before being able jump, it's not that much reactive. And I also want to know if it's ok to change the Rigidbody's velocity in the Update method, if not then how can I link the inputs in the Update with the physics in the FixedUpdate.
Answer by Marioooo · Aug 11, 2021 at 07:07 PM
Hi!!
This is an effective way but not the best way...
Let's say you're running... an then jump. By doing this the way you're doing it, the running velocity, is set to zero, cause the X force is now Zero.
the right way would be:
rb.AddForce(new Vector2(0, jumpForce), ForceMode.Impulse)
the impulse is to make it happen in one frame, google force mode to understand what i mean
don't mess around with velocity unless you really want to kill all other forces.
also the movement should be handled in update and not in fixed update, cause fixed update happens several time on the same frame. move the "move" line to the input method and before the jump check hope this helps!