# Rigidbody.MovePosition/Rotation makes wall collisions stupid

Hello. I have a problem with how Rigidbody.MovePosition and Rotation get handled by physics wall collisions. Basically, I made a very simple hovering car that moves with Rigidbody.MovePosition and my car moves almost perfectly how I want. Except that when I move my car up against a wall, it starts to penetrate and vibrate.

Here’s the code I have so far:

``````var moveSpeed : float;
var turnSpeed : float;
var moveSensitivity : float;
var turnSensitivity : float;

private var car : Rigidbody;
private var joystick : Joystick;
private var stickPos : Vector2;
private var vectorPos : float;
private var vectorRot : float;
private var carPos : float;
private var carRot : float;

function Awake ()
{
car = this.rigidbody;
joystick = GameObject.FindObjectOfType (Joystick) as Joystick;
}

function FixedUpdate ()
{
//Get the joystick values and apply them to a movement/rotation vector
stickPos = Vector2 (joystick.position.x, joystick.position.y);
vectorRot = stickPos.x * turnSpeed * Time.deltaTime;
vectorPos = stickPos.y * moveSpeed * Time.deltaTime;

//Smooth out the movement and rotation of the car
carRot = Mathf.Lerp (carRot, vectorRot, turnSensitivity * Time.deltaTime);
carPos = Mathf.Lerp (carPos, vectorPos, moveSensitivity * Time.deltaTime);

//Move and rotate the car using the movement vectors
var relativeTrans : Vector3 = this.transform.TransformDirection (Vector3.forward);
var rot : Quaternion = Quaternion.Euler (0, carRot, 0);
car.MovePosition (car.position + relativeTrans * carPos);
car.MoveRotation (car.rotation * rot);
car.velocity = Vector3.zero;
car.angularVelocity = Vector3.zero;
}
``````

Does anyone have a clue as to why it stutters like that? I think it has something to do with car.position and it being added to. But that’s how the manual states it as.

How would you go about making, say, a cube that moves along the ground with the arrow keys and bumps into colliders properly? I can’t help but feel that I’m missing something massively important as this is something that I assume people would know how to do on day one.

From a quick glance at the docs:

Rigidbody.MovePosition is for kinematic rigidbodies.

kinematic rigidbodies don’t respond to forces, though they do apply them to non-kinematic rigid bodies.

I think you have a case of the unstoppable object and the unmovable wall.

1 Like

Are you sure? I’ve seen posts and code examples where people use MovePosition for non-kinematic rigidbodies. But I don’t know how to make my car move without it vibrating when pushing against a wall.

Surely there must be a way to do what I want.

I had to change my rigidbody from Interpolation-Interpolate to Interpolation-None.

I wish I figured it out sooner. Was driving me nuts for days.

2 Likes

@theinfomercial Works like a charm!

I don’t know if you really want to set the rigidbody velocity to zero after you move it.

``````car.velocity = Vector3.zero
car.angularVelocity = Vector3.zero;
``````

This is unpredictable.
The rigidbody should stop by itself when it collides with something.

The API even warns you not to set the velocity like this:
http://docs.unity3d.com/ScriptReference/Rigidbody-velocity.html

EDIT: I just realized this thread is 4 years old, sorry.