- Home /
collision between two objects without using OnCollision,etc.
Hey, I asked this a couple days ago but didn't get an answer so I'll try to ask this again simply.
Is there a way in Unity to check collision between two objects WITHOUT using the events OnCollision, etc.? I'm looking for a function thats something like checkCollision(obj1, obj2).
Thanks!!
EDIT: just to be more specific, the reason I want to do this is because I have multiple objects that can collide with each other. I was wondering if there is a function like the above because, for example, in an rts type game such as startcraft/sc2, you can put down objects, but obviously you can't put down objects if they are touching other objects.
This is what I'm doing. I have a controller object/script that allows you to put down objects. The instance is created, and it follows your mouse, until clicked, which is when it is put down.
Now, I can obviously create a script, and set the object to isTrigger, and check on the object itself if is colliding with something else, and then get that value from the controller, etc. etc. However that is slightly troublesome. I would rather just do something like above, where I can just check if the currently dragged object is colliding with anything, easily, and quickly, from any object/script.
Can you give a reason? $$anonymous$$aybe if you explain what you want to accomplish someone/I could tell you a work around?
Answer by Owen-Reynolds · Apr 16, 2011 at 02:32 AM
Something like Starcraft has an underlying 2D grid, with each square marked as full/vacant. To check for a collision, you check if the 3x3 squares of your Barracks are marked empty.
Unity has a built-in sphere vs anything checker: http://unity3d.com/support/documentation/ScriptReference/Physics.OverlapSphere.html.
It doesn't have a cube overlap that I know of. Writing one to account for rotations is a bit of a pain.
Your answer
Follow this Question
Related Questions
get angular velocity change from collision 0 Answers
OnCollisionEnter inside FixedUpdate? 1 Answer
script trying to access a null gameobject's collider... can't fix 2 Answers
WALL collision detection problem... help!!!! 0 Answers
Simple collision? 2 Answers