I bring yet-another-drag-with-mouse question (I am using Unity with C#), but with a less common particular detail: the existence of obstacles in the middle of the way trough which dragging occurs (3D space, not 2D).
Let me explain. Suppose I have a plane over which I want to drag a cube called "obj" .That's easy. Here is my simple implementation for that:
void Update () {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if(Physics.Raycast(ray, out hit, 1000000))
obj.transform.position = new Vector3(hit.point.x,0.25F,hit.point.z);
}
It works. However, suppose that I also have a few other cubes over the plane, which are the obstacles. Obviously, when the player moves "obj" over the plane, such movement should be blocked by the obstacles. And then, while colliding with the obstacles, "obj" should move only snipped to the sides of that obstacle. If mouse is moved and "obj" stops colliding with obstacles, free dragging-style movement resumes again.
To make the challenge harder, I am trying hard to achieve that without the use of RigidBody components at the obstacles (the dragged object can have it). Any ideas on what is the most efficient way of achieving that? Many thanks!
EDIT: Commentators have brought to my attention that I should mention that objects are allowed to rotate when snapping.
EDIT 2: Considering the difficulty of the original formulation, I changed the question allowing the use of Rigidbody components at the dragged objects. The solution just can not use Rigidbody components at the obstacles.