tower defense type game AI

BlitzMax Forums/BlitzMax Programming/tower defense type game AI

ckob(Posted 2008) [#1]
I'm trying to make a tower defense game basically you have a level where you can place towers that will shoot mobs and the mobs need to detect each tower and move around the towers, what I was thinking of doing is having the mobs use 4 spheres place on the sides,front and behind and if one of the spheres collides then the mob turns to another sphere and moves in that direction however I think this might be slow once 30-40 mobs get on the screen. So can anyone give me any ideas on the AI for this? I thought about A* but im not sure if that will do it either...by the way this is 3d.


tonyg(Posted 2008) [#2]
Depending on how good you want the AI to be you might want to a google search on Influence Maps.
However, the sphere collision sounds workable even with 30-40 mobs. Scene graphs might be something which can help.


Dreamora(Posted 2008) [#3]
1. Use a virtual grid (-> equidistant path nodes in grid style)
2. Calcualte a path on the empty route
3. Whenever a tower is placed, check if it intersects with the current path for the mobs. If so, recalculate it for the distance that the tower "cut".
4. you might apply a smoothing algorithm afterwards to make sure they don't run straight up to the tower and "move around it" if they could have approached it with a slightly different path before


As the path can only change when a tower is placed, this is a very simple, yet cpu time saving way ...


Czar Flavius(Posted 2008) [#4]
As an advanced suggestion... if the mobs must go past a tower, perhaps a stronger creature or one more resistant to the tower's attack should go first to draw fire and let others safely pass?


Dreamora(Posted 2008) [#5]
Wouldn't make sense as the tower has decision AI as well and it will rate the "faster to kill" mob higher unless the harder one would cost more lives.


ckob(Posted 2008) [#6]
I am currently researching the Influence Maps they seem to be a good way to do it, I will try my first way though and if it works stick with that. I was thinking of doing the following pseudo code of coarse.

moveentity(mob),0,0,.1
if mobs collision sphere collides with tower pointentity(mob) at next collision sphere then continue moving forward.