How do I check if an object is within bounds of another object?
I am doing a 2D game and doing some drag'n drop and have check if the object getting dragged is within the bounds of another object. If false the dragged object have to be destroyed.
There might be an easier way than using bounds and since I'm new to Unity I'm open for every kind of solution. I do prefer UnityScript though.
Thanks in advance:)
2 Answers
2
use built-in mesh colliders like a box collider and set isKinematic to true then do an OnCollisionEnter as referenced in the docs
http://unity3d.com/support/documentation/ScriptReference/Collider.OnCollisionEnter.html?from=Collision
you could also roll your own system but perhaps the above is easier...
Hey - HR - I’d love to know how you did this. I come from Flash too and I don’t really get the collider thing. Did you find a way to do it with bounds? Would much rather do it that way.
What are the shapes of the objects involved? Are they convex? Non-convex? (Etc.)
– j_y_kNot convex. Simply just a plane above another plane.
– anon30604785...and completely square. I'm coming form flash where I simply would check my rectangles or coordinates.
– anon30604785Squares are convex :) Anyway, if you're using the built-in physics system, you might be able to use colliders, as harmless suggested. Otherwise, you could just perform the test manually (containment tests involving rectangles and other convex polygons are pretty straightforward).
– j_y_kWell alright - maybe I should do some reading in geometry:) Thanks for your inputs. As you can see in my below comment I've got it working but now have some other problems.
– anon30604785