You can do this in a few ways... I'm guessing that your enemy units are all individual sprites, and not one sprite that represents a whole group of enemies?
If they're all separate, you can set the target to the projectile when the projectile is being created (on shoot). You could make some instance variables for the arrow, or the soldier, and call them something like TargetX and TargetY. Then you can pick the enemy that's closest to your defending unit, and set the instance variables TargetX and TargetY to be the coordinates of the enemy.
You can then use the coordinates (pick by comparison) to tell your soldier or arrow which unit to apply damage (and also to trigger to destroy your arrow sprite). Simply compare the TargetX and TargetY values to the coordinate position of the enemy. I would recommend setting a comparison RANGE of say, 3-5 pixels or more (depending on the size of your graphics).
Hopefully this hint helps. If you still have problems just let me know here and I will see if I can make a quick example.
~Sol
Hi, thanks for the atention.
The sprites aren't individual sprites, they are all clones made by the system to defend the "CPU's" castle.
My event sheet of the soldier being attacked by another soldier is:
EnemySoldier is overlapping Soldier
Is "Attack" animation playing.
Animation frame="4"> Soldier subtract 25*EnemySoldier.PickedCount from life.
The event for the arrow is:
Soldier On collision with Arrow > Subtract 15 from vida.
And then i'd like to maintain this codes and add the necessary to make sprites choose just one enemy at time to fight, and the arrows hurt just one enemy even when they are overlapped.
A great exemple of what I'm talking is the game EpicWar 1 and 2. Even when the troops are all overlapped, they aim at only one sprite at time.