- Home /
Trigger to some, Collider to others
Alright, should be a quick n' easy question. Just doing some due diligence before I commit to an alternative.
Can one collider on an object act as both a collider and a trigger, depending on the interacting object's layer?
Since I'm reasonably sure that's a no, based wholly on the following, what alternative would be preferable? Please ignore the apparent size/shape discrepancy I mention in my proposition.
Scene Description:
250+ boxes, kinematic rigidbodies, static once instantiated, box colliders
50+ spheres, free rigidbodies, sphere colliders
Boxes don't interact with each other, only with spheres.
3 Alternatives:
Adding 250 sphere colliders as triggers, which likewise only interact with our 50 spheres or...
Performing 250 * 50 distance checks, perhaps distributed over several frames or...
250 frequent calls to Physics.OverlapSphere() looking for those 50 spheres (masking)
All 3 would give me what I need, which is OnTriggerStay() or a fair approximation, but which method sounds most appropriate from a performance standpoint?
Thanks a million,
Answer by Bloodyem · Feb 03, 2014 at 05:40 PM
Yes you can. You need to call the collider and set the trigger to true.
collider.isTrigger = true;
Right, but it needs to function as both, even in the same frame, depending on the interacting object's layer, for instance.
In the same frame might be a little tricky. Possibly what you could do is add a second collider and make that function as a trigger on a different layer.
I figure that's the best option, and am mostly asking to verify it's the best of the 3 I suggest in my question. Thanks for the reply.