- Home /
Jumping: Endless Runner,Hey can anyone help with this endless runner script ?
Hey guys trying to make my character jump in this endless runner game script tried changing the script to no avail
,Hey pretty new to Unity and I can't get my character controller to jump the script has no errors but when the game is launched the character doesn't jump any clues as to why ? ?
Answer by thomaslijohnson · Jul 24, 2021 at 02:38 PM
I'm not too good at unity either, but i think it's because you're multiplying a positive number (2 * jumpHeight) with a negative number (gravity). I think the best way to add gravity is to just add a rigidbody and set the gravity value in the editor. Even if you can't do that, just use AddForce like this:
If (IsGrounded && Input.GetButtonDown("Jump"))
{
rigidbody.velocity.y = jumpHeight;
}
else if (!IsGrounded)
{
rigidbody.AddForce new Vector3(0, gravity, 0);
}
// I'm assuming that IsGrounded is only true when the player is touching the ground
It's probably not the most optimised way of doing it but it should work
Your answer
![](https://koobas.hobune.stream/wayback/20220613040735im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Can't get platforming character to jump 2 Answers
Character floats down after jumping 0 Answers
Jumping only once (2D) 2 Answers