I have already looked for solutions to this problem online, but none of them seem to solve my problem. To make a chracter controller, I followed this tutorial. This is the second part in a longer series. The first part worked perfectly for me. The second part however, when finished made me unble to move. The problem is that my code thinks I’m never on the ground, and thus my velocity vector is constantly decreasing on the y-axis (falling).
My code:
private bool Grounded() {
return Physics.Raycast(transform.position, Vector3.down, moveSettings.distToGrounded, moveSettings.ground);
}
private void Jump() {
Debug.Log(Grounded());
if (jumpInput > 0 && Grounded()) {
//Jump
velocity.y = moveSettings.jumpVel;
}
else if (jumpInput == 0 && Grounded()) {
//Grounded
velocity.y = 0;
}
else {
//Falling
velocity.y -= physicSettings.downAccel;
}
}
I don’t think it’s a problem with the code, as it is exactly identical to what is used in the tutorial. The player object is a simple, standard cube with a standard box collider, straight from the add menu. What’s basically happening, is that I’m unable to move because the y of my velocity is increasing way too much. This happens because the Grounded() method, basically a substitute for Physics.Raycast
, always returns false.
I’m really out of ideas on how to fix this, that’s why I’m here.