In my CharacterController
I noticed that isGrounded
flickers anytime I only apply y
during the move, i.e. when the character is standing still and only gravity is acting on it.
The update function looks like this:
void Update()
{
groundedPlayer = controller.isGrounded;
var direction = gamepad.leftStick.ReadValue();
var vy = velocity.y;
var vx = direction.x * speed;
var vz = direction.y * speed;
if (groundedPlayer && vy < 0)
{
vy = 0f;
}
if (gamepad.buttonSouth.wasPressedThisFrame && groundedPlayer)
{
vy += Mathf.Sqrt(jumpHeight * -3.0f * gravityValue);
}
vy += gravityValue * Time.deltaTime;
velocity = new Vector3(vx, vy, vz);
controller.Move(velocity * Time.deltaTime);
}
So I did some experiments of applying a constant downward velocity to determine at what speed isGrounded
became stable, during which I also tracked Time.deltatime
to determine what gravity
value would result in the needed downforce. It was here that I noticed that I was running at ~600fps.
Once I set Application.targetFramerate = 60
in Start()
everything started behavior properly. Is this a bug or a known limitation of the CharacterController
. I don’t really want to hardcode targetFramerate
and trying to figure out how I should fix this properly.