Tower Defense style targeting
JGary321
Member Posts: 1,246
I am creating a TD type game. I have 10 mobs come in each wave. One right after the other. I need a good way to target the mob & then shoot at it. Each wave spawns 1 type of mob. I currently have no idea how to do this. I have tried constraining the mobs attribute, but it only fires at the 'first' mob. It won't fire at any other mobs even if the first is not in range anymore. I need a way for it to switch to the next mob in line. Anyone have any clues?
Comments
I have my Tower (T) & a Range actor (x) & Mobs (m).
xxxxxxx
xxxxxxx
xx T xx
xxxxxxx
xxxxxxx
/\
||
||
||
mm
When Mobs collide into Range actor, I have my projectile spawn at Towers coords & move to Monsters coords. However it only constrains 1 mobs coord. So if the tower doesn't kill it before it leaves it's range, it won't attack anything else until the mob is dead. Then it will lock onto a new target.
This may better help understand, so we can solve this. I know I can't be the only one interested in a TD style game
-JGary
Basically it is this for one tower and attacking the closest target.
When an enemy collides with the "sight range" of the tower, it calculates is distance between itself and the tower's position and compares that value with some global attribute (closestEnemy), and if it is smaller, then constrain that distance and its position to game attributes which the tower can target. When the tower sees it is colliding/overlapping with an enemy, it just shoots towards those game attributes.
You may see why it might only work with one tower because you would need a tower actor and a range finder actor(if you want to dynamically modify its range)which goes on top of the tower. It would be easier if you could get info directly from another instance, then you could easily add more than one tower.
I haven't tested it, so its just theory now.