Input delay when using CharacterController.Move function

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);
    }
2 Likes

Ok, I understand the problem now - I’ve wrongly assumed that GetAxis will always return either 0, 1 or -1. It turns out that even when playing on keyboard it can return values in between these.
This means that I should normalize vector only if it’s magnitude is bigger than 1 - otherwise it will sometimes make it bigger then it should be. After adding a condition before normalizing vector everything works like it should.

9 Likes

thanks bro, you fixed my problem