Hi,
I’m trying to build a tower defense game and sp far it’s working well. I do however have a problem.
Right now my tower checks there’s anenemy within reach, and if there is, the tower will fire.
The problem I’m having is to determine what enemy is the first one (closest to the exit)
this is no problem the first few waves, but for example if you have a wave with some slow enemies first and some fast enemies behind them (which will be fast enough to pass the slow ones) my towers will fire at the slow ones first even if the fast ones are ahead.
This boils down to the fact the when I check if the tower should fire I basiclly do this;
for t=1,towersLayer.numChildren do for e=1, enemyLayer.numChildren do ... if within range, fire.. end end
which will catch the slow enemies first because theey are added first.
Does anyone have a bright idea on how I can go about this?
Thanks!