Selecting and assigning units + Finding nearest units

Some questions about how to do some unit selection and finding nearby units:

How can you draw a box and select all friendly units within it?
How can you select multiple units and then get them all to take the same action? For example, all attack something or all move somewhere.
How to find the nearest enemy unit?

I spent quite a lot of time trying to work these things out, with no success. :confused:

  1. On the end of the draw box thing have every friendly unit check if its x > boxes leftmost part, x < boxes rightmost part, y > than its uppermost part an y < than its lowermost part, if all four are true, set unit to selected.

  2. Have a variable called “selected” (or whatever) for each enemy then only have it do the actions if selected = 1.

  3. This is the trickiest one, Game Develop doesn’t have any find nearest thing so you have to make one, it involves checking an enemy objects distance to the object in question, then storing that distance to a variable (let’s call this variable “dist”), repeat this for every enemy, checking each time if the new distance is shorter then the “dist” variable, if it is replace the “dist” var with the new distance and set this object to the new closest enemy.

Thanks very much! :smiley:

I’m struggling to understand how to impliment case 3. How can I make the game check the distance to every enemy for every one of my units? i.e. I want each of my units to check every x seconds where is the nearest enemy (if they are not already busy doing something) and move to them. The moving I can do and the checking if they are already doing something, but I don’t know how to check every enemy for every one of my units. >.<

You can do it like this (not tested, so don’t know if it works) :