Rigidbody.MovePosition
public void MovePosition(Vector3 position);
Description:
Moves the rigidbody to position.
Use Rigidbody.MovePosition to move a Rigidbody, complying with the Rigidbody's interpolation setting.
If
Rigidbody interpolation is enabled on the Rigidbody, calling
Rigidbody.MovePosition results in a smooth transition between the two
positions in any intermediate frames rendered. This should be used if
you want to continuously move a rigidbody in each FixedUpdate.
Set
Rigidbody.position instead, if you want to teleport a rigidbody from
one position to another, with no intermediate positions being rendered.
例子:
using UnityEngine; using System.Collections; public class DemoController : MonoBehaviour { public Rigidbody cube1; private float speed = 20; private void Update() { //cube1.position = cube1.transform.position + Vector3.forward * Time.deltaTime * speed; cube1.MovePosition(cube1.transform.position + Vector3.forward * Time.deltaTime * speed);//MovePosition方法使物体移动更平滑 } }