Overlapping physics objects

I have a situation where due to a user action a physics object can suddenly change shape - imagine some balls floating around in a space and clicking one should make it suddenly double in radius.

However there’s a fairly large chance that aftwerwards the new shape could overlap other shapes in the same space. When this happens the shapes seem to bind together and get stuck within each other - the objects are restricted via a 6DoFConstraint to movement only in the x and y planes if that makes any difference. I am sure when this has previously happened in physics engines i’ve worked with, the engine has worked to incremently push the objects apart (sort of tunnelling them out of each other if that makes sense)…

An obvious answer to the problem is delaying the rebuild until there is sufficient space for the object to change it’s shape, but that will be a pain to code as they aren’t regular shapes (of course!) Just wondering if I am missing something obvious.

You can use a shape cast to find overlapping object and push them:

https://doc.babylonjs.com/features/featuresDeepDive/physics/shapeCast

Yeah, I could have sworn Havok did this as well. What happens if you try without the constraint?

In my post of a spinning top, the top occasionally gets stuck in the ground and stands straight up. There are no constraints on either the top or the ground.

No different without the constraint :frowning:

In my experience when two physics objects overlap they just fall in love and never let go of each other.

1 Like

@Greg_Findon By chance, are you using shapes of type PhysicsShapeType.MESH?

For example, I’ve seen that a PhysicsShapeType.BOX is able to stay stuck inside a PhysicsShapeType.MESH. However, if you use a PhysicsShapeType.CONVEX_HULL instead, the box eventually be pushed outside