Loop though an array to see which is closest to player?

i have a dummy object that you place within the world that you can add locations in the default properties to, to create an array of them. I want to be able to find which is the closet to the player ( which I am casting in ) as this will be used to spawn an AI. the only way of doing it I can think of is lots of comparing and would be long as hell and wouldn’t work as I don’t know how many locations will be added be designers. here is what I have attempted so far but is totally impractical

anybody provide any advice / assistance would be greatly appreciated

Hey, let’s see what we can do here.

So first i need some information:

You have this array with positions and you want to check which if all these positions is the closest?

If yes, you could use a “for each loop” for that. Pull out the array and instead of typing “get” you type “for each” and select the for each loop.
The algorithm to find the smalest element of an array is the following (i hope this works xD):

http://puu.sh/cSlYD/f32e733067.png

http://puu.sh/cSlZU/bbf870d385.png

Also why are you getting the capsule components location? Using the “Get Actor Location” from the player would give you the position of the player directly.

that works! thanks alot :smiley: and i thought world location might of been more appropriate but obv not :stuck_out_tongue: