Smooth Rigidbody Drag around Objects

Hey guys,

I’m working on a game where there are several rigidbodies arranged in a playspace and the player can select one of the rigidbodies and drag it around. I’ve gotten this to work ok, but there are a few issues I’m having that I’m unsure how to resolve.

  1. Is there any way to have the dragged object smoothly glide around the edges of obstacles? For example, if there is a row of objects in the way, I’d want the dragged object to stop at the edge of the objects, but then still move up and down, “gliding” against the edges of the objects. I’ve tried using MovePosition, but there is some interpenetration that occurs.

  2. When the dragged object hits other rigidbodies in the area, it pushes these other rigidbodies out of the way. I don’t think I can make the rigidbodies kinematic because I still need to apply gravity to them. Is there any way to make a rigidbody immovable by another rigidbody?

If you are effectively pausing the simulation when you are dragging your objects around, then you could make everything else kinematic while paused except the object you are dragging. Don’t set Time.timeScale to 0 in this case and the simulation will continue to run while you drag the object around. You can drag it by applying a force (with increased drag on the object so it won’t oscillate around the mouse), or by using a spring joint connected to a temporary kinematic object moved by the mouse (this kinematic object should not collide with anything).

If you aren’t pausing the simulation, then your could just make the mass of the object you are dragging very very small in relation to everything else and it won’t push them around by very much.