Tower Defense style targeting

JGary321JGary321 Member Posts: 1,246
edited November -1 in Working with GS (Mac)
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

  • ktfrightktfright Member Posts: 964
    do you use timers for the shooting?
  • JGary321JGary321 Member Posts: 1,246
    Yup, but that only effects how fast they shoot. The way I did my shooting was this:

    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
  • JGary321JGary321 Member Posts: 1,246
    Any Mods have any direction to steer the ship on this one?
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    I can only think of one method right now, but it includes a few rules and game attributes. But it kindof works only for one tower, or one instance of a tower per prototype.

    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.
Sign In or Register to comment.