My player is a rigidbody cube with a box collider that can push other "NPC" rigidbody cubes that also have a box collider. These NPC cubes have restricted movement either in horizontal or vertical direction. If the player pushes a cube that can only move horizontally into a cube that can only move vertically, the cubes start clipping. I recorded the whole situation in this video. Note that the NPC cube on the left has frozen X position, while the one on the right has frozen Z position.

I know that one way of preventing this would be to increase the mass of the NPC cubes, but that would only resolve the problem proportionally to the increased mass (the higher the mass, the lower the clipping), and at some point my player is not strong enough to move the NPC cubes anymore.

How can I solve this?

  • \$\begingroup\$ How are you moving the objects? The only physically correct way is to apply impulses and forces. \$\endgroup\$ – Shadows In Rain Apr 29 at 5:34
  • \$\begingroup\$ I'm moving them by changing their velocity as rigidbodyComponent.velocity = new Vector3(horizontalInput * moveSpeed, rigidbodyComponent.velocity.y, verticalInput * moveSpeed); \$\endgroup\$ – Liisjak Apr 29 at 14:45
  • \$\begingroup\$ In the video, the red block pushes the middle block, and the middle block clips through the left block. To be clear, what you want is to prevent the middle block from clipping into the left block? \$\endgroup\$ – Kevin Apr 29 at 20:51
  • \$\begingroup\$ Have you tried playing around with the Solver Iterations / Solver Type in the project Physics Settings? \$\endgroup\$ – Kevin Apr 29 at 20:56
  • \$\begingroup\$ Yes, I want to prevent the middle block from clipping into the left block. Changing the Solver Iterations and/or Solver Type did not affect the behaviour. \$\endgroup\$ – Liisjak Apr 30 at 19:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.