Legacy Documentation: Version 4.5.0

Script language:

  • JS
  • C#
  • Boo
Script language

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

MovePosition(position: Vector3): void;
void MovePosition(Vector3 position);
def MovePosition(position as Vector3) as void

Parameters

positionThe 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)))