- Home /
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?
hey,
i got the same problem. Did u ever find a solution or came up with your own code?
btw. static checkbox has no effect on colliders, see "static checkbox"
Answer by BoredKoi · Jul 16, 2011 at 05:23 PM
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.
Sphere checks (and capsule checks) are straightforward, of course... but there's no function there to check box colliders, particularly non-axis-aligned ones.
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...
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.
Answer by Bunny83 · May 20, 2012 at 01:00 PM
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.
Collisions with triggers are detected as well, accordingly to a specific parameter that indicates to include or exclude them from the test result.