|
模型导入Unity后,挂载伤移动脚本,模型移动后会全身一直发抖,位置发生微小偏移,移动脚本挂载到Cube则正常不会抖,请大神解下惑!
下面为移动脚本代码:
public float speed; //角色移动速度
private Vector3 target; //目标位置
private bool isOver = true; // 移动是否结束
void Start()
{
}
void Update()
{
if (Input.GetMouseButtonDown (0)) {
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit hitInfo = new RaycastHit ();
if (Physics.Raycast (ray, out hitInfo)) {
if (hitInfo.collider.name == "Plane") {
target = hitInfo.point;
target.y = 0.5f;
isOver = false;
}
}
}
MoveTo (target);
}
private void MoveTo(Vector3 tar) //让角色移动到目标位置
{
if(!isOver)
{
Vector3 v1 = tar-transform.position;
transform.position += v1.normalized * speed * Time.deltaTime;
if(Vector3.Distance(tar,transform.position)<=0.05f)
{
isOver=true;
transform.position=tar;
}
}
}
}
|
|