Hello forum, I’m not totally sure if my question falls into the “Physics” directory but here it is.
I need to know what objects are currently colliding with one specific trigger object at one specific time.
I don’t need to have behaviours happen when that trigger object enters or exits collisions : I just need to have the list of things it’s actually colliding with at the moment I call one specific script. I would love to write something like : GameObject[ ] theCollidingObjects = myCollider.listofCurrentCollisions
but unfortunately it does not work like this.
Is there a simple solution to do that ? Or do I have to write OnCollisionEnter and OnCollisionExit functions, where objects log themselves in and out of a log book everytime they enter or exit, so that I can have their list when I need it ? It sounds like an awful waste of CPU resource…
Well that’s what I finally did : all interesting objects in the scene have a OnTriggerEnter and OnTriggerLeave procedure, where they register in and out of a logbook everytime they cross the trigger object’s path, so that when I need it I just have to read the logbook to see who’s here.
It still feels like an awful waste of computing time though.
This sounds like the solution I’m looking for, but for some reason I can’t make it work.
I have my “interesting” objects with one rigidbody and sphere collider each, and my “trigger” object with one box collider (in “trigger” mode) and one rigid body (that I added because SweepTestAll needs it).
But when I SweepTest the trigger’s object Rigidbody, the code always returns a void array, even though I make sure that there is at least one “interesting” object inside. I suppose that I’m doing something wrong, but what ?