(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)); rigidbody.MovePosition(newPosition);
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.