Before updating to Windows 10 you may need to return your Pro license. More information here

Manual collision check

Given two colliders -- ones, in fact, which have no rigid body and are marked "static" and "trigger" -- is it possible to manually check for overlap between them? I guess I could unstatic them and give them rigid bodies and see what happens, but ideally I'd like to do this during Start(), so that's not an option there. I suppose I could implement the collision test myself, for the collider pairs I need, but I'd really like to avoid that if possible. Any clever ideas?

more ▼

asked Jul 16, 2011 at 03:05 PM

avatar image

2k 16 20 39


i got the same problem. Did u ever find a solution or came up with your own code?

May 20, 2012 at 12:06 PM ne0r

btw. static checkbox has no effect on colliders, see "static checkbox"

May 20, 2012 at 01:02 PM Bunny83
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Manual collider checks are done via two static functions...Physics.OverlapSphere will return an array of the colliders touching the caller object and Physics.CheckSphere (quicker) is a bool that indicates overlap/contact exists.

more ▼

answered Jul 16, 2011 at 05:23 PM

avatar image

451 1 1 10

Sphere checks (and capsule checks) are straightforward, of course... but there's no function there to check box colliders, particularly non-axis-aligned ones.

Jul 16, 2011 at 06:39 PM sneftel

Yep, that's a more specific problem (boxes) -- how about collider.bounds.Intersects? Or if not the collider (speaking to axis-alignment) try renderer.bounds.Intersects perhaps...

Jul 16, 2011 at 07:25 PM BoredKoi

Unfortunately, both of those are world-space axis-aligned. It's frustrating, because of course Unity is more than capable of doing the check, for any collider pair (other than concave meshcolliders); it simply deigns not to expose that functionality.

Jul 16, 2011 at 08:49 PM sneftel
(comments are locked)
10|3000 characters needed characters left

You can use Rigidbody.SweepTest to check manually for collisions. I'm not sure if collisions with triggers are detected as well, but it's worth a try.

Collision detection is done by the physics system. Colliders are pure passive objects. Only rigidbodies can perform collision tests.

more ▼

answered May 20, 2012 at 01:00 PM

avatar image

97.5k 57 301 529

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Jul 16, 2011 at 03:05 PM

Seen: 12122 times

Last Updated: May 20, 2012 at 01:02 PM