best methods for tracking numerous targets (tower defense auto targeting)

part12studiospart12studios Member Posts: 620
edited June 2012 in Working with GS (Mac)
Hey everyone,

so i'm working on making a tower defense-ish game and basically what i have is a number of enemies that move towards the cannons and past them like say.. fieldrunners.. and the tricky part to me is figure out how to have the cannons evaluate who is closest to shoot at.. and the number of enemies could vary from a few to a couple dozen..

any advise or tips would be super appreciated.. i was able to make a single cannon lock onto a specific target, but it gets hairy for me when it looks to find another target.. then things fell apart.

Thanks!
Caleb

Best Answer

  • fadamionfadamion Posts: 309
    Accepted Answer
    Well just check the distance with magnitude
    Set up distance from enemy there are all kind of help for this on here.
    looks like this.
    self.distance is greater then magnitude(self.position.x-game.playersx,self.position.y-game.playersY)

    put all your enemies in a tag group called enemies

    when enemy comes in range lock on

    have a lock on attribute for each turret once locked on don't search for new target till locked on target dies or is out of range then search again.

Answers

  • part12studiospart12studios Member Posts: 620
    i've seen a few templates in the list of public games, but they really seem kinda hackish.. i'm not sure if its possible with GS. I like to think it is, but i'm just not sure i see how GS could have a dynamic number of targets on the screen and have numerous turrets checking distances between multiple moving enemies..

    Perhaps this is something a writable table would be good for, but this seems like it might not be very efficient with all the constant checking going on.

    Thanks
    Caleb
  • part12studiospart12studios Member Posts: 620
    aaahh i've never really used tags before.. but yea that makes a ton of sense. i'll try that for sure!

    Thanks!
    Caleb
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited June 2012
    There is a video on the cookbook YouTube site on how to tell if an actor is still on the scene this may help you design your code.

    Also this video I made on turret AI may help you add some randomness to the targeting system but since I made this video I found that linking location through in scene data is much more efficient but it means unlocking actors and can't be done if actors are spawning unless recycle is used.



  • part12studiospart12studios Member Posts: 620
    UPDATE:

    @fadamion Ok so i generally get what you mean but having never used Tags.. i'm not sure how that would work exactly. To do a track target, i have used "Rotate to Position", but in my options i see "actor tags" but i'm not sure.. do i do (actor tags)=tag name?

    I guess the question is ok once i understand how to use the above tag name stuff, and once a given object passes for being closest.. how does the "rotate to position" know which x y coordinates to use and how to update them.

    As usual i'm probably making it too complicated.. but the idea of dealing with numerous objects sharing some common global variable sounds like a conflict waiting to happen.

    Thanks!
    Caleb
  • part12studiospart12studios Member Posts: 620
    @FryingBaconStudios i'm going over that video now.. i do think that i might be able to approach the game with the unlock / recycled actors possibly.. but yea i'll see how you're approaching things in this video! Thanks so much!
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited June 2012
    @part12studios you're not making it more complicated..it is very complex to build an AI. It is really going to be a combination of many different techniques. The trick is to spend the time to refine the code until you come up with code that is slimmed down for good processor performance. Most people just go with the first think that kinds works. When I write complex code I may toss aside ten ways that work until I get the most slim and processor effective version.
  • part12studiospart12studios Member Posts: 620
    edited June 2012
    @fryingbaconstudios thanks for the insight!

    Does anyone have any leads / tips on how to work with Tags in game? I thought tags were just for filtering actors in the actor view.. but i now see that tags can be accessed in the formula editor but i don't understand the syntax.

    NOTE: Today's been a crazy day at home with the family so i haven't had a chance to watch that video.. if Tag syntax is in there thats awesome. I'm just not sure if your approach is the same approach that @fadamion is talking about

    Thanks
    Caleb
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    What that would do is allow you to build some generic code so say like collisions you can set an actor to collide with all actors having that tag. Also for you're targeting system you could tell it to fire on actor with tag that is the closest x y position. Have you watched the video in the cookbook on determining distance between actors?
  • part12studiospart12studios Member Posts: 620
    edited June 2012
    I never seem to find anything useful in the cookbook.. Maybe I'm not using it right or something.

    "distance" didn't turn up anything.. nor did "between actors" come up with anything specific to what you're talking about. Maybe i'm missing something about it..

    I would love to know effective ways to measure distance.. i think magnitude comes into play somehow.. according to fadamion's suggestion

    Thanks!
    Caleb
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    No go to YouTube and search for the gamesalad cookbook videos
  • part12studiospart12studios Member Posts: 620
    ah ok cool :) thanks!
  • lukey5227lukey5227 Member Posts: 111
    Distance between actors? You have a right triangle, right? Distance between x's is a, distance between y's is b. Got this in your head? c is the straight distance?

    A^2 + B^2 = C^2

    square root of (A^2 + B^2) is c, the distance in pixels between the two actors.
  • part12studiospart12studios Member Posts: 620
    @lukey5227 thanks for the math breakdown! :) I'll have to see how that looks in GS. Up till now most of my games haven't had to rely on much complex math, but this TD game will clearly be a first to really require some forethought.
  • lukey5227lukey5227 Member Posts: 111
    @part12studios Complex math? Thats how all GS games are made. If you're not usin' any, you're not doin' it right, partner. ;)

    Plenty of things require math. See if you can understand a lot of the functions such as max, min, random, cos, sin, and many others. You will find that many will be useful to make things possible or lots shorter to do.
  • part12studiospart12studios Member Posts: 620
    I've made six games so far and a seventh will be done at the end of next week without using anything more than random, so yea lots can be done without much math beyond the basics. However in this case, its another story.
  • lanmindlanmind Member Posts: 29
    @lukey5227 Hi are there any resources you could point me towards to help me understand se of the trigonometric functions?

    I've looked over some cos & sine material but am having a hard time understanding some terms used. Maybe a place for beginners?
Sign In or Register to comment.