Today, I've met strange behavior in unity 3D mode. Currently developing the 3D game such as FPS type of game. 



Here is basic code. 

The problem happened when press Left, Right key several times after. My player continues rotating even if release left, right key.


    private void MoveByPad()

    {

        float h = CnInputManager.GetAxisRaw("Horizontal");

        float v = CnInputManager.GetAxisRaw("Vertical");


        if (v > 0)

            transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);

        else if (v < 0)

            transform.Translate(-Vector3.forward * moveSpeed * Time.deltaTime);

        if (h < 0)

            transform.Rotate(Vector3.up, -turnSpeed * Time.deltaTime);

        else if (h > 0)

            transform.Rotate(Vector3.up, turnSpeed * Time.deltaTime);

    }





To solve the issue. Append code to stop the angular velocity to set zero. 

Check 'Red marked' code 


    private void MoveByPad()

    {

        float h = CnInputManager.GetAxisRaw("Horizontal");

        float v = CnInputManager.GetAxisRaw("Vertical");


        if (v > 0)

            transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);

        else if (v < 0)

            transform.Translate(-Vector3.forward * moveSpeed * Time.deltaTime);

        if (h < 0)

            transform.Rotate(Vector3.up, -turnSpeed * Time.deltaTime);

        else if (h > 0)

            transform.Rotate(Vector3.up, turnSpeed * Time.deltaTime);

        else

        {

            rb.angularVelocity = new Vector3(0, 0, 0);

        }

    }


Remember that this way is not going to work player need to rotation effect by some other factor.

By this reason, this is temporary code.

Is anybody knows this issue and the best way to solve the issue?