Question by
vapi · Mar 20, 2016 at 12:27 PM ·
movementcharactercontrollerframerate
CharacterController's Move frame-dependency
Hi,
So imagine there is a piece of code like this:
void Update()
{
if (charController.isGrounded)
mVel.y = 30f;
mVel.y -= 1f;
charController.Move(mVel * Time.deltaTime);
}
and it bounces a character controller up and down. The problem is that it is frame dependent: the controller jumps a lot higher when FPS is locked by v-sync, even though I am using Time.deltaTime.
It works perfectly fine when using FixedUpdate + Time.fixedDeltaTime, but I am trying to understand what I am missing when using Update.
Comment
Best Answer
Answer by vapi · Mar 20, 2016 at 07:45 PM
Okay, since "mVel.y -= 1f" is considered as applying acceleration to velocity, the value is also supposed to be fractioned by delta time, so then the velocity is applied to position in the Move call, which also must be multiplied by delta. So this works as expected:
void Update()
{
if (charController.isGrounded)
mVel.y = 30f;
mVel.y -= 1f * Time.deltaTime;
charController.Move(mVel * Time.deltaTime);
}