- Home /
JUMP LOGIC
I am trying to apply a JUMP effect on my game object. However I am doing this by applying force in y direction. However it is not giving an exact effect of jump as this force is not constant. How can I do this ?
What kind of movement logic are you using? Rigidbody, CharacterController or a Translate (or something else)?
Answer by guitarxe · Dec 04, 2013 at 04:12 PM
If you want to use Unity's physics to accomplish this, then the logic is simple.
First you apply a large amount of force in the up direction, Vector3.up
public int jumpForce;
void FixedUpdate()
{
if(Input.GetKeyDown(KeyCode.Space)
{
gameObject.rigidbody.AddForce(Vector3.up * jumpForce);
}
}
Then, be sure your GameObject
has a RigidBody
component and it is using gravity
. You can also check the physics settings of your project and modify the gravity settings, but by default these are set to real world -9.81 for the y axis.
This will first propel your GameObject up, and then unity will handle the gravity. If you do not see any movement when you apply the force, then you are not applying enough. Try higher values.
Alternatively, you can lower the mass of the object.
Of course, you'll need to write additional force to further the jumping logic, such as making sure the character cannot jump again while still in mid-air.
Answer by bhavya_812 · Dec 04, 2013 at 05:49 PM
However I have already tried this.. The force does not seem to stay constant
Of couse the object's velocity will not stay constant. There is gravity acting on it. What exactly do you want to accomplish, and what are you getting?
For a really basic movement script check the documentation of CharacterController.$$anonymous$$ove And just add a CharacterController to the GameObject you want to move.
Your answer
![](https://koobas.hobune.stream/wayback/20220613123410im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
2D 360 degress platformer example needed 0 Answers
physical force feedback 0 Answers
Strange Physics being applied to objects issue. 1 Answer
Rigidbody.MovePosition not really smooth 2 Answers