best methods for tracking numerous targets (tower defense auto targeting)
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
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
-
fadamion Posts: 309
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
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
Thanks!
Caleb
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.
@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
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
"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
A^2 + B^2 = C^2
square root of (A^2 + B^2) is c, the distance in pixels between the two actors.
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.
I've looked over some cos & sine material but am having a hard time understanding some terms used. Maybe a place for beginners?