Support Forum

Multiplayer game with multiple targets

Hi,
I purchased the pro version and I’m wondering what would be the best approach for calculating which one of the players (targets) is closest to the seeker?

I’d like to be able to switch and update the seeker’s target automatically based on which one of my targets is the closest one to the seeker

Hi

You can use something like this:

var ai = GetComponent<IAstarAI>(); // AIPath/RichAI/etc.
// Disable the agents own path calculation logic
ai.canSearch = false;
// Find a path to the closest target
var path = MultiTargetPath.Construct(ai.position, listOfTargets, null, null);
path.pathsForAll = false;
// Make the ai calculate that path
ai.SetPath(path);

I haven’t tested this, but I think it should work.
You will need to run this code regularly to make the agent update its path (see also Documentation for some details which might be useful)

Thanks for the reply.
One more thing, are there any ways is pathfindig project pro to set the chasers “wake up radius”? I’d like my chasers to only chase the closest player when the player is close enough to the enemy.

That’s game logic. There’s nothing for this in the package itself.