Why does RigidBody.MovePosition ignore collisions?

I want my object to collide with a wall (i.e not be able to walk through it), from all docs I read MovePosition should take this into account:

private void FixedUpdate()
{
   rb.MovePosition(transform.position + direction * movementSpeed * Time.deltaTime);
}

I’ve made sure all layers are detecting each other in physics settings and neither is marked as a trigger. What am I missing? It’s still just moving straight through the wall.

8002085--1029059--upload_2022-3-28_17-22-32.png

Your Rigidbody is kinematic. It will only respect collisions with MovePosition if it is not kinematic.

I tried that too, and after googling a bit it did say that MovePosition should work for both. Either way I tried it and didnt fix my issue.

Weeell, movePosition is a tricky one – anyone can mess it up. It works on kenimatic RB’s, so you have that part right. It’s also working as intended – it snaps exactly where you put it, no matter what.

The idea is that if you want blocking and bouncing-off, use a normal RB and give it a speed. movePosition is for when you were going to use position= but you also want it to shove things out of the way as it moves. That’s kind of an odd case. I think it was there before and Unity kept it, since why not.

1 Like

It “works” for both, in that it makes both things move. But only the dynamic body will respect collisions.

As above, this has nothing to do with MovePosition, you’re just not understanding what a Kinematic body is. Move the body manually in the editor over something you’re expecting it to produce a collision response to and hit play. Notice how it doesn’t move? Welcome to what Kinematic bodies are for; they do not react to forces such as gravity nor forces you manually apply and they don’t have a collision response because it’s not what they’re for. If you want that then you use a Dynamic body!

Kinematic bodies can use physics queries to detect their environment and not moved into overlap with other things based upon it i.e. capsule-cast, raycast etc.

So you know, there’s a dedicated Physics sub-forum here.

1 Like