First of all I did a search and found a thread but didn't find any definite solution.
I have about 100-200 planets scattered across the layout, and probably somewhere in excess of 1000 ships all in different locations. I need each ship to be able to pick which planet is closest and go there.
How would I go about picking the closest planet?
Develop games in your browser. Powerful, performant & highly capable.
I solution to this could be something like this; each planet has a value called "distance". Run a For Each loop on the planets and set the distance value to the distance between it and the player( the expression for that is distance(x,y,x2,y2) ). Then merely use the "Pick Object With Lowest Variable" condition to get the one you want. And here's a simple CAP to demonstrate:
A ball will light up if it's closest to the mouse. Hope this helps.