I’m trying to make a platformer for my first project, and I have the moving around working. But jumping is proving a problem. I am using a function to make the player jump:
rigidbody.AddForce(Vector3.up * jumpSpeed);
but the upward momentum seems isolated to the individual frames where the jump key is pressed, meaning a very unreliable/unrealistic jump arc. Also the model just hangs in the air and falls very, very slowly.
The model is 4 units tall, has a rigidbody with drag and angular drag set to 0, and mass set to 1. Gravity is set to -9.81. I’ve tried playing with the mass, to no avail, and it seems like changing gravity is the wrong approach.
I can’t figure out what is slowing the models decent, and the other answers I’ve looked at on this site either don’t apply to my situation, or don’t have answers yet. Can you help me?
here some advice for jumping with physics:
when you jump make sure you can’t press jump again (double jump).you can do that with bool that set to true when press jump and false when get back on the ground. then check for it state when press jump. this way you will avoid apply multiple “addforce” in long jump press. it will make the jump more consistent.
you can set the gravity multiple on your player’s rigidbody. this will make him fall faster. it will effect your player only and not the whole project.
you may want to try to apply the force as impulse for the jump. (forceMode.impulse)
Unity - Scripting API: ForceMode.Impulse
I see the problem now, I apologize for not seeing it early, and thanks for the help.
When I was trying to set the horizontal velocity I was also setting the vertical velocity to 0. I have replaced the Y parameter of “movement” with the object’s rigidbody.velocity.y.
It seems to be falling normally now.