- Home /
My Jump Does not work,My Jump does not work
My character will not jump at all. I have tried many solutions but to no avail. (this is 3D) How to I fix this? I have tried using RigidBody gravity and the Rigidbody.AddForce but it does not work either.
void Update()
{
Vector3 velocity = Vector3.zero;
if (Input.GetKeyDown(KeyCode.Space))
{
Debug.Log("jumping");
velocity.y = _jumpForce;
}
else
{
// Apply gravity
velocity.y -= _gravity;
}
// Move the controller
_controller.Move(velocity * Time.deltaTime);
}
This works for other people but not for me. I have an attached CharacterController. ,After trying many solutions, I am not able to make my character jump. I had simplified my code, and tried to debug the issue but to no avail. The script also logs "jumping", showing that it iterates through the section where the jump code is.
// Update is called once per frame
void Update()
{
Vector3 velocity = Vector3.zero;
if (Input.GetKeyDown(KeyCode.Space))
{
Debug.Log("jumping");
velocity.y = _jumpForce;
}
else
{
// Apply gravity
velocity.y -= _gravity;
}
// Move the controller
_controller.Move(velocity * Time.deltaTime);
This is someone else's code that seems to work, but not for me. I tried using the RigidBody gravity system and using rb.AddForce but that doesnt work either. Even after removing the rigidbody component, I am still unable to jump. I have a CharacterController Attached.
Answer by Captain_Pineapple · Nov 11, 2021 at 10:02 AM
Hey there,
first up, Rigidbodys will not help if you are using a character controller.
The issue that you specifically face here is that your jump basically works - but it is so small and tiny that you cannot see it.
Why is that?
Becaus you set the velocity to something positive for 1 frame only. That beeing the frame in which you press space. The idea to then substract the gravity is alright but since you initialize the velocity vector to zero each frame you get a result like this over the frames:
velocity = -gravity
velocity = -gravity
velocity = -gravity
velocity = -gravity
velocity = jumpforce
velocity = -gravity
velocity = -gravity
so get rid of this your velocity variable should not be a local variable but a member of your class.
In addition you will have to check when you hit the ground. You should only ever accellerate downwards if you actually are in the air.
Your answer
![](https://koobas.hobune.stream/wayback/20220613045236im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
I cant move my character,My character wont move 0 Answers
Player Controller "Horizontal" input convert to "left" and "right" 1 Answer
How to replicate cylindrical collider boundries 0 Answers
Best way to control a Cube Like Character 0 Answers
Problems with the movement of custom character controller 1 Answer