Closest of multiple targets?

I’m having a little trouble understanding how to set up a multitargetpath with the example in the docs, or even whether its what I should be using.

I have a character (eventually a small crowd) that should be attracted to the closest of a few targets around it. Think flies attracted to lights turning on and off. For a base setup I have a seeker, AIPath, and a character controller on my character, A* object with a working Astar Path, and my target is just a new gameobject for now.

The example says to put it onto an object that has children and a seeker. In my case which object would that be, and what do I set as the target on my character’s AIPath?

Thanks.

Ok so you have a bunch of target points (I will from now assume they are in a Vector3 array called “targets”) and you want to find the one which is closest to you and find the path there.
This is easily done like this:
`
//Find the Seeker component
Seeker seeker = GetComponent();

//Start a multi target path
seeker.StartMultiTargetPath (transform.position,targets,false, OnPathComplete);`
The above will start a multi target path from the current position to “targets”. The key thing here is that the third parameter “pathsForAll” is set to false. The docs say
pathsForAll: Indicates whether or not a path to all end points should be searched for or only to the closest one
So with that false, only the shortest path will be returned (it can be got like any other path).

the AIPath cannot be used directly, but it requires a few small changes.
First, change ‘target’ to an array of Vector3s (or transforms if you want) and name it ‘targets’. Then in the SearchPath function, replace seeker.StartPath(…) with the StartMultiTargetPath call in the above code. Probably a few other fixes as well, but it should be easy enough I think.

Hope it helps.