- Home /
What tower defence turret AI approach is best-practice?
G'day guys, I'm writing a tower defence game and currently have a functional system where the player clicks to 'deploy' a turret, after which any enemy that enters that turret's collider triggers an event which adds it to a list of available targets. The tower shoots at it until the target is either out of range (left the collider) or dead. When I implemented a raycast to check LOS, it occurred to me that the trigger+array system might not be the most efficient long-term.
I've read (and experimented with) using Physics.OverlapSphere and I've encountered another approach that relies on one global array of all enemies, and every turret in the game is constantly raycasting each enemy to see if it is in LOS/range, etc.
What I'd like to know is which approach (especially if there are some I'm unaware of) is the most efficient? I know efficiency could be debated, but I figured I'd ask as I imagine many of you blokes have written TD games before.
Cheers guys.
Answer by garner · Apr 09, 2012 at 01:07 AM
It doesn't seem like much of an issue unless all the turrets were checking an array of players all the time. If players aren't within firing radius remove them from the array.
It's more the 'big picture' I'm concerned about. There'll eventually be quite a few enemies in-play so I was hoping I might learn what method(s) are the lightest on the CPU.
Your answer
Follow this Question
Related Questions
Applying Damage To A Player Objects From An NPC 1 Answer
Make a turret shoot multiple targets 1 Answer
Gimple lock? ... help me please 2 Answers
trouble with my lookAt script 0 Answers
Raise AI aim 2 Answers