Tower Defenese Help

FajlajpFajlajp Member Posts: 666
edited May 2013 in Working with GS (Mac)
Hi
I've run to a dead stop in my game...
I've try to make a tower defense game(just like bloons tower defense) I've succeded with all the things execpt one. I can't get a turret to shoot the enemy who is closest to the exit. I have done so the actor shoots in a specific range. I have tried different methods but does not work when you have multiple turrets. Please help me as soon as possible. I've worked all day trying to figure this out...
//Fajlajp

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    It's a difficult thing to do. I don't know how helpful this will be but it's a demo I made for someone who wanted a targeting system. Drag the red square into an enemy's radius.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited May 2013
    One idea I've had is to have each enemy check its distance (magnitude) to a tower and then if it's own distance is greater than the greatest distance (game.farthestEnemyDistance), change game attributes to its own x/y position and have the tower always target those game attributes. Easier said than done!

    Another idea, since now you've got me thinking about it, is to have a bunch of invisible checkpoint actors along the path that the enemies travel. Each checkpoint is numbered (self.checkpointNumber). When an enemy overlaps with a checkpoint, change its own self.myCheckpointNumber to the checkpoint it just overlapped and if that checkpoint number is greater than the highest checkpoint reached (game.HighestCheckpoint), then change game.HighestCheckpoint to self.myCheckpointNumber. If an enemy's self.myCheckpointNumber is equal to game.HighestCheckpoint, constrain game.enemyTargetX/Y to its self.positionX/Y and have the tower always target game.enemyTargetX/Y.

    ***Or forget about checkpoints and distance and just use self.Time, assuming that the enemies are traveling in a more or less straight path and the enemy that has been on the screen the longest is always closest to the exit.

    Phew!

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Sign In or Register to comment.