Rigidbody.MoveRotation

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual
public void MoveRotation(Quaternion rot);

Parameters

rotThe new rotation for the Rigidbody.

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 rotations 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.

//Attach this script and a Rigidbody to your GameObject. To do this click the GameObject, click the Add Component button in its Inspector, and go to Physics>Rigidbody.

using UnityEngine; using System.Collections;

public class Example : MonoBehaviour { //Make sure you attach a Rigidbody in the Inspector of this GameObject Rigidbody m_Rigidbody; Vector3 m_EulerAngleVelocity;

void Start() { //Set the axis the Rigidbody rotates in (100 in the y axis) m_EulerAngleVelocity = new Vector3(0, 100, 0);

//Fetch the Rigidbody from the GameObject with this script attached m_Rigidbody = GetComponent<Rigidbody>(); }

void FixedUpdate() { Quaternion deltaRotation = Quaternion.Euler(m_EulerAngleVelocity * Time.deltaTime); m_Rigidbody.MoveRotation(m_Rigidbody.rotation * deltaRotation); } }

Teleports the object (rather than a smooth transition) if it has isKinematic set false.

Did you find this page useful? Please give it a rating: