Pick Closest?

For questions about using Classic.

Post » Mon Jan 05, 2009 2:56 pm

Hi,

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?
Follow me on Twitter @evgLabs
B
33
S
14
G
4
Posts: 251
Reputation: 4,049

Post » Mon Jan 05, 2009 3:26 pm

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:

Pick Nearest

A ball will light up if it's closest to the mouse. Hope this helps. :)
Moderator
B
97
S
36
G
19
Posts: 1,584
Reputation: 17,692


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 1 guest