Basic AI - Unit follow player
by Phillip O'Shea · in Torque Game Builder · 02/10/2008 (6:34 pm) · 3 replies
I'm having trouble getting units to follow the player nicely.
Basically, I have set up my scene so that it is broken into one large grid. As an object moves around the grid, it tells the scene that the cells he is on are active. This is so that my units can move to the player, but not get too close to him.
When a unit is told to follow the player, it will check to see the players location and then head in that direction until he cannot get any closer.
The problem that I get is when there is an obsticle in the way, the unit cannot recognise that there is anything there. I have investigated breadth-first pathing, but I just don't understand it very well.
Does anybody know how I can create a basic pathing script for my AI?
Cheers
Basically, I have set up my scene so that it is broken into one large grid. As an object moves around the grid, it tells the scene that the cells he is on are active. This is so that my units can move to the player, but not get too close to him.
When a unit is told to follow the player, it will check to see the players location and then head in that direction until he cannot get any closer.
The problem that I get is when there is an obsticle in the way, the unit cannot recognise that there is anything there. I have investigated breadth-first pathing, but I just don't understand it very well.
Does anybody know how I can create a basic pathing script for my AI?
Cheers
About the author
Head of Violent Tulip, a small independent software development company working in Wollongong, Australia. Go to http://www.violent-tulip.com/ to see our latest offerings.
#2
02/21/2008 (12:32 am)
Check out the 'moveTo' function in the API docco. You can simply give it a position and the entity will move to it. It will not, however, guide itself around any obstacles in the way if you have collisions suitable enabled on the object, and you will have to implement some kind of pathing behaviour. Breadth and depth first searching for AI purposes will 'work' but are generally way too slow for anything beyond trivial. Dijkstra's [url]http://en.wikipedia.org/wiki/Dijkstra's_algorithm#Running_time[/url] might be a little bit better also, but what you really what to look into is the A* algorithm.
#3
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=9711
02/21/2008 (12:44 am)
I've since dropped this project, but for anyone who is interested I found a resource created by Phil Shenk which implements A* into TGB, which works without mods in 1.7.1.www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=9711
Torque Owner Doc308