当我缓慢移动鼠标时,动画会严重停顿。这就是它的样子。
如您所见,快速移动鼠标时,动画完全按照我希望的方式执行。问题是它们在缓慢移动时不会移动。我想要一些有关如何消除或减少口吃的帮助。
这是我的设置:
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");
}
动画和混合树设置:
答案 0 :(得分:2)
我认为您需要的是一些平滑或插值。在Move函数中一个非常简单的插值函数如下。
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);
}