- Home /
Adding gravity to character and grounded checks are not working?
Hello, I am trying to remake the first person controller as a learning experience. I set up CharacterController.Move and everything, but I can't seem to get the gravity yet.
I tried:
if(cc.isGrounded)
{
verticalVelocity = 0;
}
else
{
verticalVelocity += Physics.gravity.y;
}
I plug in verticalVelocity into:
cc.Move(forwardMovement, verticalVelocity, sideMovement);
I then tried to Debug.Log(verticalVelocity), but every second or so it changes from 0 to -0.15...
What is the problem? Is the CharacterController.isGrounded not working or am I understanding something wrong?
Also, I try to jump when CharacterController.isGrounded, but sometimes I can't jump.
Can someone please help me understand?
First of all gravity should be deducted and not added to vertical velocity since it is supposed to pull you down. Also when you are grounded you should have an if statement that checks if you press a button and then add a jump value to vertical velocity ( opposite of gravity, meaning +=) Hope its understood, and in my answer i assume your grounded checks are workin properly.
From what I know, Physics.gravity.y is a negative value (-9.81), so deducting it will just contradict the negative and make the player go up. Also, I already have a jumping check, but I didn't include it in here. Basically, what it does is when jump is pressed, it adds to the vertical velocity, just like you said.
Your answer
Follow this Question
Related Questions
CharacterController isGrounded toggles value 2 Answers
Gravity still being applied with unity CharacterController 0 Answers
Player slides down slope. 0 Answers
How to program gravity for planets? 3 Answers