Rigidbody.MoveRotation
public void MoveRotation(Quaternion rot);
Description:
Rotates the rigidbody to rotation.
Use Rigidbody.MoveRotation to rotate a Rigidbody, complying with the Rigidbody's interpolation setting.
If
Rigidbody interpolation is enabled on the Rigidbody, calling
Rigidbody.MoveRotation will resulting in a smooth transition between the
two positions in any intermediate frames rendered. This should be used
if you want to continuously rotate a rigidbody in each FixedUpdate.
Set
Rigidbody.rotation instead, if you want to teleport a rigidbody from
one rotation to another, with no intermediate positions being rendered.
例子:
using UnityEngine; using System.Collections; public class DemoController : MonoBehaviour { public Rigidbody player; public Transform enemy; private float speed = 10; private void Update() { if (Input.GetKey(KeyCode.Space)) { Vector3 dir = enemy.position - player.position; dir.y = 0; Quaternion target = Quaternion.LookRotation(dir); player.transform.rotation = Quaternion.Slerp(player.rotation, target, Time.deltaTime); } } }