I’m still learning Unity and programming in general so this may be an easy question to answer. I searched the forums and manuals and spent 3 days scratching my head to no avail so here goes:
First a little background. I’m using the book "Programming Game AI by Example (Mat Buckland - great learning tool) and I’m playing around with steering behaviors and converting all the C++ code to Unity JavaScript and taking advantage of Unity’s features.
I have several game agents wandering around on their own, avoiding obstacles and walls and maintaining separation from each other. The physics is being handled by Unity (using forces and rigidbodies for movement) and raycasts for obstacle detection and wall avoidance.
For separation I have a gameController component passing an Array of agents to all the agents so that each agent can figure out where other agent are located so it can maintain separation.
So far so good - all according to the book.
But now I want to change all that to take advantage of Unity’s colliders.
I want to place a sphereCollider around all the agents and give it a neighborhoodRadius value and make the collider a trigger.
My hope is that this one collider will replace all the raycasts for wall detection and obstacle avoidance as well as get rid of the array of agents that every agent has to sort through to find out who is within it’s neighborhood.
Okay, all that aside - here’s my question:
function OnTriggerStay
function OnTriggerEnter
function OnTriggerExit
So far I can successfully use these functions to detect when agents enter/exit/stay within a collider and become a “neighbor.” But I need to pass an array of these neighbors to my steering behaviors.
How can I make an array of the neighbors using OnTriggerStay (collider : Collider)? The array would have to be constantly resized as agents enter and exit the collider. I have been playing around with some code, but getting nowhere.
I hope I am describing this correctly. And again, I am learning to program so if I am not understanding the concept of OnTriggerStay, please let me know.
Thanks for any help.
Mitch