Reputation: 85
When I move my mouse slowly my animations stutter heavily. Here is what it looks like.
As you can see when moving the mouse quickly the animations preform exactly how I want them to. The problem is they dont when moving slowly. I would like some help on how to eliminate or reduce the stuttering.
Here is my setup:
void Update()
{
var x = Input.GetAxis("Mouse X");
var y = Input.GetAxis("Mouse Y");
if(Time.time > nextActionTime)
{
nextActionTime += period;
CheckIdle();
}
if (!paused && !sideScroller)
{
if (walking)
Walk();
//Animation detect if mouse has moved
if (Input.GetAxis("Mouse X") > 0 && Input.GetAxis("Mouse Y") == 0 && !running && !fire)
{
mouseMoved = true;
rightR = true;
//RotateRight();
VisualBlendTree();
Debug.Log("Moving Right, Bitch!");
}
if (Input.GetAxis("Mouse X") < 0 && Input.GetAxis("Mouse Y") == 0 && !running && !fire)
{
mouseMoved = true;
leftR = true;
//RotateLeft();
VisualBlendTree();
Debug.Log("Moving Left, Bitch!");
}
if (Input.GetAxis("Mouse Y") > 0 && Input.GetAxis("Mouse X") == 0 && !running && !fire)
{
mouseMoved = true;
upR = true;
//RotateUp();
VisualBlendTree();
Debug.Log("Moving Up, Bitch!");
}
if (Input.GetAxis("Mouse Y") < 0 && Input.GetAxis("Mouse X") == 0 && !running && !fire)
{
mouseMoved = true;
downR = true;
//RotateDown();
VisualBlendTree();
Debug.Log("Moving Down, Bitch!");
}
if (Input.GetAxis("Mouse X") == 0 && Input.GetAxis("Mouse Y") == 0 && !running && !fire)
{
mouseMoved = false;
leftR = false;
rightR = false;
upR = false;
downR = false;
Debug.Log("Moving Nowhere, Bitch!");
}
Move(x, y);
}
}
void CheckIdle()
{
if (!Input.GetKey("a") && !Input.GetKey("s") && !Input.GetKey("d") && !Input.GetKey("w") && !mouseMoved && !fire && !running)
Idle();
Debug.Log("Checkint Idle");
}
private void Move(float x, float y)
{
animatorComponent.SetFloat("VelX", x);
animatorComponent.SetFloat("VelY", y);
}
public void Idle()
{
running = false;
vibrating = false;
leftR = false;
rightR = false;
upR = false;
downR = false;
animatorComponent.Play("CannonIdle");
Debug.Log("Cannon Idle Called");
}
Animation and Blend Tree Setup:
Upvotes: 1
Views: 1125
Reputation: 724
I think what you need is a little smoothing or interpolation. A really simple interpolation function within the Move function would be as follows.
private Vector2 lastMouseVel;
private void Move(float x, float y)
{
Vector2 interpolated = (lastMouseVel + new Vector2(x, y)) /2;
animatorComponent.SetFloat("VelX", interpolated.x);
animatorComponent.SetFloat("VelY", interpolated.y);
lastMouseVel = new Vector2(x, y);
}
Upvotes: 2