Ok here is my code for gravity. ApplyGravity() gets called in Update(). The default values of the variables mentioned in this block of code are as follows:
gravityModifier = 9.81f
baseGravity = 50
resetGravityValue = 1.2f
jumpSpeed = 6
I have an issue where the isGrounded boolean of the character controller sometimes randomly flickers off and then back on when moving. Also, on a sort of unrelated note, the gravity/isGrounded values change when standing still, which I dont believe should happen. Can anyone help me with this? The code if down below. Thanks.
void ApplyGravity()
{
if (!characterController.isGrounded)
{
if (!resetGravity)
{
gravity = physics.resetGravityValue;
resetGravity = true;
}
gravity += Time.deltaTime * physics.gravityModifier;
}
else
{
gravity = physics.baseGravity;
resetGravity = false;
}
Vector3 gravityVector = new Vector3();
if (jumping)
{
gravityVector.y = movement.jumpSpeed;
}
else
{
gravityVector.y -= gravity;
}
characterController.Move(gravityVector * Time.deltaTime);
}