how could I break apart or unstick two intersecting rigid bodies

(The camera script has a “Node” property which you can set to the cube or plane prefab)


I’m trying to do a classic: Be able to drag and drop rigid bodies around while having them collide and bounce with any other rigid bodies along the way. Of course, I’m also running into a classic issue: if I drag fast enough, I am able to intersect the body I’m dragging right into another body. Eventually PhysX might break them free from each other, but ideally I’d want the intersection to not happen in the first place. I’m moving the rigid body by doing rigid body.

        Vector3 newPosition = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, -Camera.main.transform.position.z));

The suggestions that I’ve seen in the forum are usually along the lines of using the DragRigidBody script or the DragObject script. But neither feels right since they incur a noticeable lag between one dragging a finger / mouse to the desired position and the object following after the fact. Actually, considering the perceived velocity at which the object can be dragged, I don’t see any difference between using those scripts vs the approach I showed above: moving directly to the new position, if done at a comparable velocity, won’t result in bodies intersecting and getting stuck.

Anyway, so since the two drag scripts don’t feel snappy enough, I was thinking what if I wait until after the bodies intersect and in OnCollisionEnter(Collision) for instance, apply some force to break them apart, given the contact points of the collision, or given some insight from inspecting both colliders involved in the collision?

Does anyone have any thoughts on what aspect(s) of the collision to base the direction and force to break the bodies apart?

This is what I mean by the bodies getting stuck together if I drag one of them too fast towards another:


These 2 planes are at the same z coordinate and are therefore intersecting. Eventually, depending on how the intersect, the physics engine will impart some force that separates them so they no longer intersect. But ideally they shouldn’t be allowed to intersect in the first place.

Having read all the comments, I believe the answer to your question is:

your colliders must be cubes.

As you say below, I literally mean “cubes” – pretty much exactly the same length on all sides

Here is my demo project … please grab the middle cube and move it.

NOTE – the “cube” aspect has fixed your problem. (Please tick this answer :slight_smile: ) But you are indeed on the fundamental limits of physX. Using my demo, try moving REALLY REALLY FAST. Of course, you will break it - but then - that would happen ion the real world, am I correct?

Hope it helps!

Regarding purely the issue of getting the “feel” you want (which is what i first thought you were asking.)

It is very difficult to do this. I think in this case you can and should “just move” the object at all times to exactly where the finger is. It will “smash out of the way” any other objects it encounters. You may have to additionally add “fling” … when you let go, turn on the rigidbody again and give it a velocity based on it’s recent finger-speed.