How to trigger turning animation on moving the mouse?
I am new to Unity animations. I am trying to make a 3rd person game. I have animations for my character to turn half or quarter left and right as per how long I hold the A and D key. I have set it up by making the animation part of blend tree. I have two parameters, Speed and TurnSpeed. W sets Speed to 0.5 which starts walking animation, W + LShift sets speed to 1 which starts running animation. For turning, I use the following:
float turn = Input.GetAxis("Horizontal");
And then set it's value to the TurnSpeed param, and in the Blend Tree, 0-0.5 TurnSpeed makes quarter turn if idle, or a slow turn if walking and running. TurnSpeed 0.5-1 makes half turn on idle and sharp turn on walking and running. It is working fine. I also wan't the turning to happen on mouse turn as done in most 3ps. So I used following code:
float h = horizontalSpeed * Input.GetAxis("Mouse X");
transform.Rotate(0, h, 0);
This looks fine when turning while running or walking, but in idle, it looks unrealistic, so, I want to trigger the animation of idle turn when I turn my mouse. I tried passing the h value as TurnSpeed, but it doesn't work properly, the animation looks very discontinuous as it switched rapidly from idle to turn whenever I turn the mouse. So how should I achieve what I want?
Your answer
![](https://koobas.hobune.stream/wayback/20220612225215im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Walk towards mouse cursor 0 Answers
Animation not playing when moving third person character by navmeshagent 0 Answers
If Mouse cursor is above an object, start animation (without click on It) 2 Answers
Character gets locked into idle animation after reloading of level 2 Answers
how do you make a 3rd person controller with no turning animation? 0 Answers