Detecting which direction LookDetecting will move in.

Hi,

I’m working on a project using much of the structure of the Unity Survival Shooter tutorial as a basis and I’ve stumbled upon something I can’t quite figure out.

I’ve got the following code to handle turning:

void Turning ()
    {
        Ray camRay = Camera.main.ScreenPointToRay (Input.mousePosition);
        RaycastHit rayHit;

        if (Physics.Raycast (camRay, out rayHit, rayLength, floorMask))
        {
            Vector3 playerToMouse = rayHit.point - transform.position;
            playerToMouse.y = 0f;

            Quaternion newRotation = Quaternion.LookRotation (playerToMouse);
            playerRigidbody.MoveRotation (newRotation);
        }

    }

I’d like to add in two animations I have for turning left and right. However I’m not sure how to manipulate the code so that it can detect when the player is turning clockwise and anti-clockwise.

I assume its not as easy as detecting whether playerToMouse y rotatoin is greater or less than the current rotation y because obviously it eclipses between the 364 and 0 degrees.

Assuming that moving the mouse left/right rotates your object you could just check the old/new x axis position of the mouse via rayHit.point.x