Mecanim "turnonspot" with mouse and not WASD

Ok so I am trying to get my character to execute the “turn on spot” animations found in the locomotion demo using the mouse and not the horizontal and vertical axis (wasd).

This is the code that works for WASD (as found in the locomotion demo DoJoy Class)

 Vector3 rootDirection = root.forward;
    
    float horizontal = Input.GetAxis("Horizontal");
    float vertical = Input.GetAxis("Vertical");
    
    Vector3 stickDirection = new Vector3(horizontal, 0, vertical);
    Vector3 CameraDirection = camera.forward;
    CameraDirection.y = 0.0f; // kill Y
    
    referentialShift = Quaternion.FromToRotation(Vector3.forward, CameraDirection);
    
    moveDirection =  referentialShift * stickDirection;
    Vector2 speedVec =  new Vector2(horizontal, vertical);
    speed = Mathf.Clamp(speedVec.magnitude, 0, 1);
    
    if (speed > 0.01f){ // dead zone
    Vector3 axis = Vector3.Cross(rootDirection, moveDirection);
    direction = Vector3.Angle(rootDirection, moveDirection) / 180.0f * (axis.y < 0 ? -1 : 1);
    } else {
    direction = 0.0f
    }

The above works as it should; the direction float goes from -1 to 1 based your change in direction and then settles back down to 0 if you are walking straight.

Now, I want to do the same thing but use the mouse instead of WASD.

So I attempted this:

Vector3 rootDirection = root.forward;
float x = Input.GetAxis ("Mouse X");
float y = Input.GetAxis ("Mouse Y");
Vector3 mouseDirection = new Vector3(x,0,y);

Vector3 CameraDirection = camera.forward;
CameraDirection.y = 0.0f; // kill Y
referentialShift = Quaternion.FromToRotation(Vector3.forward, CameraDirection);

aimDirection =  referentialShift * mouseDirection;

Vector3 axis = Vector3.Cross(rootDirection, aimDirection);
direction = Vector3.Angle(rootDirection, aimDirection) / 180.0f * (axis.y < 0 ? -1 : 1);

This does not work correctly as direction does not range from -1 to 1. Instead turning right ranges from .5 to 0 (backwards), turning left ranges from -.5 to .5 and “center” is .5 (should be 0.

So yeah, its all screwed up and I have tried changing a ton of stuff around to get it to function correctly but it seems like I am missing something.

For thoroughness here is the whole class as I have it right now.

//Root motion Controller

public static void DoJoy(Transform root, Transform camera, ref float speed, ref float direction, ref bool aim, ref float idleDirection, ref Quaternion referentialShift, ref Vector3 moveDirection, ref Vector3 aimDirection)
    {
		SoldierCamera soldierCam = camera.GetComponent<SoldierCamera>();
        Vector3 rootDirection = root.forward;
		Vector3 torsoDirection = soldierCam.target.forward;

		float horizontal = Input.GetAxis("Horizontal");
        float vertical = Input.GetAxis("Vertical");
		Vector3 stickDirection = new Vector3(horizontal, 0, vertical);
		float x = Input.GetAxis ("Mouse X");
		float y = Input.GetAxis ("Mouse Y");
		Vector3 mouseDirection = new Vector3(x,0,y);
		// Get camera rotation.    
		Vector3 CameraDirection = camera.forward;
        CameraDirection.y = 0.0f; // kill Y
        referentialShift = Quaternion.FromToRotation(Vector3.forward, CameraDirection);

		// Convert joystick input in Worldspace coordinates
		moveDirection =  referentialShift * stickDirection;
		aimDirection =  referentialShift * mouseDirection;	
		Vector2 speedVec =  new Vector2(horizontal, vertical);
		speed = Mathf.Clamp(speedVec.magnitude, 0, 1);      

        if (speed > 0.01f){ // dead zone
			Vector3 axis = Vector3.Cross(rootDirection, moveDirection);
			direction = Vector3.Angle(rootDirection, moveDirection) / 180.0f * (axis.y < 0 ? -1 : 1);
        }else{
			Vector3 axis = Vector3.Cross(rootDirection, aimDirection);
			direction = Vector3.Angle(rootDirection, aimDirection) / 180.0f * (axis.y < 0 ? -1 : 1);
		}

    }

I fixed the problem by only using this for DoJoy.

    Vector3 rootDirection = root.forward;
    Vector3 CameraDirection = camera.forward;
    CameraDirection.y = 0.0f; // kill Y
     
    Vector3 axis = Vector3.Cross(rootDirection, CameraDirection);
    direction = Vector3.Angle(rootDirection, CameraDirection) / 180.0f * (axis.y < 0 ? -1 : 1);