All my towers attack the same enemy why?

Hi mates I’m creating a TD template for the examples but I can’t get why this is happening

All the towers attack the same enemy
This is the shoot logic
What I’m trying to do is:

Every 0.25 check for all towers if distance to enemies group is below 100 pick the nearest and assign the enemy variable id to the tower variable target_id
later in other foreach check if tower target_id = enemy id then shoot.

As you can see all shoots the same enemy not the close one


The tower and its variables:

The enemies and its variables

the target id of the towers it change right but the tower not shooting the arrow to the enemy target id

I’m with this since hours and I can not figured out what’s wrong if anyone can help
If you need the source just ask and I upload to Drive.

1 Like

my stomach feeling tells me you also need a for each for the enemygroup.
does it make sense? maybe not. will it work? pretty sure it will

If you mean
Foreach tower_top
– Foreach Grade1Enemies
But in which event in the variable assign or in shooting event?

the thing is the Pick nearest always pick the last created enemy and not the closet.

I think this is because using an object variable as you have here:

image doesn’t select that object

I think you need to invert which ID you’re selecting, since you’re already doing “for each”, which will select the tower top object already for you.

So it’d be “The variable id of Grade1EnemiesGroup = tower_1_top.Variable(target_id)”

Edit: I think this will also be true for your “distance to” events. “Grade1EnemiesGroup distance to tower_1_top is below 100 pixels” instead of what you have now.

2 Likes