- Home /
Basic Tower Defense Tower AI
Hey guys im currently working on a TD game and was wondering what would be the best way to go about making the tower AI. I was thinking having a sphere collider that would get targets as they entered the collider and assign them in an array, then check to see if the tower has a target if not it will select the closest enemy in the array and fire until out of range then rinse repeat.
I am new to AI so if this isnt the best way please help me out, also i was wondering what would b an effective way of handling the projectiles to ensure that they hit the target without it actually adjusting its course.
Thanks in advanced!
That's how I'd go about the ai. As for the projectiles, just make them fast enough so any course adjustment would be $$anonymous$$or and thus wouldn't be noticeable.
Answer by pfranza · Jan 21, 2011 at 01:00 PM
That is essentially exactly how a simple AI would deal with the problem, then only addition that you may want to consider is that you may wish to prevent 'overkill' That is if an entity is already targeted by enough towers to kill it during the cycle, you will want to choose a new target. If you don't do this, then you can have the condition where all the towers target the enemy at the front of the line only, and don't maximize the fire power efficiently.
I see the problem with too many towers targeting a single enemy, but not sure how to tackle it. I was thinking of doing a check of all enemies in the array of targets and checking if they have a tower targetting them, if not target that enemy, then after each target in the array has been checked( if we still dont have a target) just select the one closest like normal...would this do the trick or would it pretty much do the same thing...thanks =D and if u kno a more effective way plz let me kno
Answer by psychicparrot · Jun 10, 2011 at 06:34 PM
If you are still looking for a solution, we have two awesome Tower Defense games complete with source code on ActiveDen.net - http://activeden.net/category/unity-3d/game-starter-kits
Sorry for the spam, but figured this might help?
Cheers!
Your answer