Legacy Documentation: Version 4.6(go to latest)
Language: English
  • C#
  • JS
  • Boo

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Rigidbody.MovePosition

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

Sumbission failed

For some reason your suggested change could not be submitted. Please try again 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 function MovePosition(position: Vector3): void;
public void MovePosition(Vector3 position);
public def MovePosition(position as Vector3) as void

Parameters

position The new position for the Rigidbody object.

Description

Moves the rigidbody to position.

Changing the position of a Rigidbody object by setting its transform.position value will cause it to "teleport" directly to the new position (ie, it doesn't move through any intermediate positions along the way). Any other Rigidbodies lying between the old position and the new one will be unaffected by the movement. Also, any colliders at the target position will react immediately with the moved rigidbody on the next update.

If you use MovePosition instead, the physics engine will trace a straight line path between the object's old position and the new one and behave as though it rapidly moved along that path between updates. Objects lying along the path will be pushed aside if necessary. This often gives a more acceptable result than changing transform.position. However, if the movements are small and frequent then the two techniques behave very similarly.

	private var speed : Vector3 = Vector3 (3, 0, 0);
	function FixedUpdate () {
		rigidbody.MovePosition(rigidbody.position + speed * Time.deltaTime);
	}
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    private Vector3 speed = new Vector3(3, 0, 0);
    void FixedUpdate() {
        rigidbody.MovePosition(rigidbody.position + speed * Time.deltaTime);
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	private speed as Vector3 = Vector3(3, 0, 0)

	def FixedUpdate() as void:
		rigidbody.MovePosition((rigidbody.position + (speed * Time.deltaTime)))