private void Update()
{
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
if (Mathf.Abs(h) > 0.1 || Mathf.Abs(v) > 0.1)
{
float newSpeed = Mathf.Lerp(anim.GetFloat("tSpeed"), 5.667f, Time.deltaTime * moveSpeed);
anim.SetFloat("tSpeed", newSpeed);
Vector3 targetDir = new Vector3(h,0,v);
Vector3 nowDir = transform.forward;
float angle = Vector3.SignedAngle(nowDir, targetDir, Vector3.up);
print(angle);
transform.Rotate(Vector3.up*angle*Time.deltaTime* rotateSpeed);
}
else
{
anim.SetFloat("tSpeed", 0);
}
}
这是我控制人物移动的代码,我在按下按钮后角色只会一卡一卡的往前移动很短的距离,但是动画已经正常往前在走了。unity版本是2018.3.6f1.
同学你好,转向用四元素,别用欧拉角,
Quaternion newRotation = Quaternion.LookRotation(targetDir, Vector3.up);
transform.rotation= Quaternion.Lerp(transform.rotation, newRotation, rotateSpeed * Time.deltaTime);
另外检查一下其他参数的设置,可以下载一下老师源码检查排除一下问题。