- Home /
Object within bounds of another object
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:)
What are the shapes of the objects involved? Are they convex? Non-convex? (Etc.)
...and completely square. I'm co$$anonymous$$g form flash where I simply would check my rectangles or coordinates.
Squares 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).
Well 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.
Answer by loopyllama · Apr 02, 2011 at 05:53 PM
use built-in mesh colliders like a box collider and set isKinematic to true then do an OnCollisionEnter as referenced in the docs
you could also roll your own system but perhaps the above is easier...
Thanks it worked but another problem occurred: When I duplicate my GameObject that hace the collider and Rigidbody attached the collision detection disappears from the cloned object.
simply post a new question:) this system wasn't intended for an evolving discussion. that is what the forums are for!
Right:) I might post another question but I think I've found a better solution
Answer by heaversm · Jul 11, 2011 at 04:00 PM
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.
Your answer
Follow this Question
Related Questions
How to Place and arrange 3D cards using Grid and Bounds 0 Answers
CalculateFrustunPlanes / TestPlanesAABB returns unexpected results 0 Answers
How can i make sound when the gameobject exit the camera? 1 Answer
LodGroup manually set Bounds 0 Answers
SpriteRenderer Bounds is Returning the Wrong Extents (Sometimes) 1 Answer