- Home /
how to make jump naturally?
I've been studying this matter but it's not easy for a beginner. This is what I want to implement. A character jumps. It goes up fast at first, gets slow down and the gravity applies at the top and fall. Like a real jump. I wonder how to control the speed.
Can anyone help me with this? Any advise will be so appreciated.
The possible solutions will depend on how you are moving your character (Rigidbody, CharacterController, Transform), and how your character interacts with the rest of the scene. For a Rigidbody, you can just do a one-time AddForce() and let gravity take over. For a Transform, you can use the $$anonymous$$athf.Sin() to calculate height over time.
Thank u so much for your comment. I will try the addforce() method because it sounds easier than the other one. But I am very interested in that method too. So can I see the Sin() method anywhere? It will be very helpful for me to find some source codes.
Here is one answer that uses a $$anonymous$$athf.Sin() to make a jump.
http://answers.unity3d.com/questions/406386/jumping-without-character-controller.html
Also the physics calculations associated with jumping are not too complex and can be used in coding a CharacterController jump.
Thanks again. You put me up by one level in program$$anonymous$$g.^^
It works beautifully. By the way, can I use tan() for the opposite case ? I mean an object move slow and getting faster. Sorry to keep asking...
Answer by SteelArrow21 · Apr 19, 2014 at 12:50 AM
Make sure the player has a rigidbody.
Javascript (May need tweaking):
var jumpForce = 400;
function Update() {
if(Input.GetKeyDown("space"))
rigidbody.AddForce(Vector3.up * jumpForce);
}
C#:
public int jumpForce = 400;
void Update(){
if(Input.GetKeyDown("space"))
rigidbody.AddForce(Vector3.up * jumpForce)
}
Adjust the jumpForce through the inspector until it gets just right. It all depends on the size of your player and the gravity. Hope this helps.
WOW!!!!!! Is it that simple? Thank u. Gotta run to test this^^
Your answer