Player can walk through walls

(I’ve already posted this question on the XR forum but it doesn’t seem like anyone visits that one so I’m posting it again here)

So I’m making a VR game using the XR interaction toolkit but the continuous move provider will let the player glitch through a wall if he just walks in to it for long enough, even when I’ve increased the colliders to be huge, set the players rigid body to have continuous collision detection and googled everywhere looking for a fix.

Nothing besides the continuous move provider is moving my player, although I’m guessing the rigid body might be moving my player as well.

Here’s all the components on my player

I have no idea what those locomotion and movement components do above. Perhaps the VR/AR/XR group knows more if they are part of a common non-Unity library? I would start there.

Either way, if you want to investigate those movers, that’s likely where your problem is, and it is likely related to this:

With Physics (or Physics2D), never manipulate the Transform directly. If you manipulate the Transform directly, you are bypassing the physics system and you can reasonably expect glitching and missed collisions and other physics mayhem.

Always use the .MovePosition() and .MoveRotation() methods on the Rigidbody (or Rigidbody2D) instance in order to move or rotate things. Doing this keeps the physics system informed about what is going on.

1 Like

In my previous project, I was using Transform to move the player (2D sprite) with a rigid body 2D. It’s good to know that it is not recommended. I guess applying velocity should be fine.

That works, but is unrelated to setting position. You can replace transform position setting with MovePosition() calls for a simple one-to-one mapping between transform moving and proper physics.

1 Like

Thanks for the help guys but I fixed the issue by recording the players last position, then checking if the current position intersects with a wall, if so then move the player to the old position.