- Home /
Accessing a collider's collisions without OnTriggerEnter or OnTriggerStay
Hello! We've been trying to find an answer to this for a while now, and simply can't seem to find a solution. Is there a way to access a specific collider's list of active collisions without attaching a script to the specific collider and implementing the OnTrigger methods?
Basically, we'd like to be able to have a single Enemy class that has collision bounds for chasing, attacking, and damaging the player. The only way we've been able to get this to work is by creating 3 different children objects, each with its own collider and script. The script implements OnTriggerEnter and OnTriggerExit to set a boolean for whether or not the player is inside the bounds.
This is great and all, but we'd really like to be able to just have the main enemy class reference 3 Collider objects and check them manually for collisions with the player. Is there some sort of method that would work like "Collision[] Collider.GetCollisions()"? From what we've been able to find, the only way to detect collisions is by making a script with the "OnTrigger" methods. Is there no way to manually check for all collisions on a collider?
Thanks in advance!
I'm having a hard time understanding what you are trying to accomplish by manually checking for the collisions... The trigger events only fire when that event occurs, otherwise there would be no change in the triggering events or collision. You can just use booleans like you were to keep track of the current state if you need the state of the collision.
$$anonymous$$aybe elaborate on what you are trying to accomplish some? From the sound of it right now, the manual checks would be unnecessary.
Well, the idea is that with manual checks to the colliders, we wouldn't have to have the extra class to keep track of collisions. In addition, "OnTriggerEnter" isn't called if the object is disabled and then enabled within the collision bounds, and "OnTriggerExit" is not called when the targeted object is destroyed while within the collision bounds. Basically, we're looking for a more efficient and accurate way of checking whether or not the player is in the trigger.
Answer by getyour411 · Feb 18, 2014 at 10:51 PM
You might want to look at physics.overlapsphere, spherecast/all and similar options. Not sure I get what you are after but after first read its what came to mind:
https://docs.unity3d.com/Documentation/ScriptReference/Physics.html
It's semantics but the title and text talk alot about collisions but OnTrigger___ doesn't have real collision data.
Edit: marking as Answer