Hello,
I’ve noticed that when I use CharacterController.Move my character never stops immediately after I stop pressing W - it always takes him a few moments (usually around 1 second) to stop.
It looks like there’s some kind of input delay, although game recognizes that none of the relevant buttons are pressed when this problem occurs.
What really baffles me is that this seems to happen only if I normalize my velocity vector so that moving forward and sideways at the same time doesn’t make you move faster (check code below for reference).
Anyone knows what might be the reason why it happens? And what would be a proper way of implementing movement without such delay?
Here’s my code:
void Update ()
{
yaw += lookSensitivity * Input.GetAxis("Mouse X");
pitch -= lookSensitivity * Input.GetAxis("Mouse Y");
pitch = Mathf.Clamp(pitch, -90, 90);
transform.eulerAngles = new Vector3(pitch, yaw, 0.0f);
Vector3 vel = transform.forward * Input.GetAxis("Vertical");
vel += transform.right * Input.GetAxis("Horizontal");
vel.Normalize(); // after I comment this line out problem disappears, but then you move faster if you walk forward and sideways at the same time
vel *= speed;
if (controller.isGrounded)
{
vSpeed = 0;
if (Input.GetKeyDown("space"))
{
vSpeed = jumpSpeed;
}
}
vSpeed -= gravity * Time.deltaTime;
vel.y = vSpeed;
controller.Move(vel * Time.deltaTime);
Debug.Log(controller.velocity);
}