Transform.Translate比Rigidbody.MovePosition移动更流畅。
Rigidbody.MovePosition()
...
public Transform target;
...
void Update()//每帧调用
{
...
testMove();
...
}
...
public void testMove()
{
Vector3 dir = target.transform.position - this.transform.position;
Vector3 vector = this.transform.position + dir.normalized * speed * Time.deltaTime;
this.transform.GetComponent<Rigidbody>().MovePosition(vector);
}
...
Transform.Translate
...
public Transform target;
...
void Update()//每帧调用
{
...
testMove();
...
}
...
public void testMove()
{
Vector3 dir = target.transform.position - this.transform.position;
Vector3 vector = this.transform.position + dir.normalized * speed * Time.deltaTime;
this.transform.Translate(dir.normalized * speed * Time.deltaTime, Space.World);
}
...
参考资料:
1.unity中让Rigidbody移动的方式
2.unity物体移动三种方式之——Transform.Translate
3.
|