Heya, I’m making a Tower Defense game and i’m trying to make my Turret’s AI system a little bit better. Here ill explain briefly how my Towers decide what to hit, because it could help a bit with the problem.
Turret AI
- The Turret waits for enemies to enter its range, once they do they are added to a list of “Possible Targets”.
- Depending on the selected “targeting” (selected from a menu in game), the Turret decides who is the best target among the ones in the list (if targeting is “Nearest”, the chosen target in the list is the nearest, if targeting is “Last”, the chosen target in the list is the lasttarget on the path, ecc…).
- The target is passed down to a bunch of components that handle rotations and such, and finally the turret shots.
Right now my Towers shoot even is something is on the way of the bullet, and what i want is a way to make Towers “skip” a Target that the Turret simply cannot hit for a reason or another. I already thought of one actually: a Linecast is shot out of the Turret to the Target’s position, and if along the way the Linecast doesn’t it the ground (or Walls or whatever), then the Target can be hit, else the target is skipped for the second best target on the list. Now this is indeed a solution to the problem but i don’t think making a Linecast for every target for every single Tower is so good for performance, so i ask you guys for a better idea.
If you have questions ask them here.
Thanks in advance!