# Check if object is overlapping

I have two objects, both of them with polygon colliders. When I click on one of the objects, I want the player to drag it on top of the other object (without collision). If there is overlap when he drops the object, it snaps to the same position as the other object. Otherwise, it resets its position.

How do I: 1) make the colliders not prevent movement 2) make it so that it detects if they're overlapping when I let go 3) Make it snap to a very specific place depending on if they're overlapping or not

• Have you checked out any of the tutorials on Unity3d.com? This would help you get an understanding of all the topics you've mentioned. – lase Jan 28 '15 at 21:33

Unity let you set a collider "as trigger". You can set the isTrigger property true on the collider of the object you start to drag. Then use Collider.OnTriggerEnter(Collider) to check if the objects overlaps some other collider. When you stop to drag an object can switch to false its collider.isTrigger.

Without more details I can't be certain if this is an acceptable solution but you might instead take the approach of scrapping the colliders completely and simply comparing the distance between the 2 objects transform.position on drop.

Alternatively, you may be able to use the information from the bounding boxes (available via the renderers) to work with the Physics library's casting capabilities. I'd look into Physics2D.BoxCastAll

i would, in order:

1. create an instance of the object you want to drag
2. set its collider to is trigger
3. change its rgba channel values to give it different color/transparency
4. on mouse button release check if overlap with OnTriggerEnter 4.b. you can optionally if objects overlap change color from blue to red, for instance
5. if they don't then move the original to the new position and destroy the dragging copy