So currently ive been using the physics.castSphere
method with a small radius to find the closest of an object with a tag.
However this is pretty performance heavy so my question is, is there a way to optimize it?
i have also been looking at keeping a list of gameobjects and just looping through those however doing that a few times a frame for each object searching also seems rather performance intensive.
Here is my case:
50 individual characters on team 1
50 individual characters on team 2
each character has to find the closest of the character from the other team.
What is the fastest and least performance heavy way of doing it?
physics.castSphere
— do you meanPhysics.SphereCast
, which fires a sphere along a ray (significantly heavier than you want) orPhysics.OverlapSphere
, which finds objects in a spherical radius (and has a non-allocating version you can use)? Do you only care about the closest object within a particular "awareness" radius, or do you still need the closest object even when it is very far away? \$\endgroup\$