- Home /
Getting rigidbody to jump by changing the velocity
Hello, I'm trying to get my character to jump by changing the velocity along the y axis. I'm making a simple snowboard/skiing game so the character slides down a hill and the velocity keeps going down as well. I'm able to get him to jump a little when he's going slow down the hill, then as he speeds up he jumps higher and higher. And then when he's going up hill, he seems to want to jump down instead of up. How do I fix this so that he jumps the same amount regardless of how fast he's going or if he's going up or downhill. Thanks
if (Input.GetButtonDown ("Jump"))
{
rigidbody.velocity.y = 2;
}
Answer by whydoidoit · May 31, 2012 at 01:35 AM
So firstly he's already got a Y velocity that you are just overwriting :) Hence the weirdness...
You could add something to his velocity:
rigidbody.velocity = rigidbody.velocity + Vector3.up * 2;
Or you are probably better adding a force:
rigidbody.AddForce(0,10,0);
Bear in mind that rigidbodies are simulated in World space - for instance adding to the Y on an inverted character will not move it towards the head, but the feet - not that this is probably your issue right now, just for reference. If you want to simulate force in the character's coordinates it's rigidbody.AddRelativeForce(0,10,0)
YES! That works! And I do want him to jump in up in world space. It's so that when I get to making a half pipe, he'll jump out and not away from the wall.
@commodore: You posted an answer, but that isn't an answer to the question above. I've converted your answer into a comment.
Answer by lqvinh2 · Jun 05, 2018 at 07:14 AM
I take player collider with enemy when using UNET. but not working.