🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Beginning AI Programming

Started by
0 comments, last by IADaveMark 12 years, 3 months ago
Hey all, I've written a few games 3D with the most basic AI (enemies that head straight toward you), and had no trouble (yay vector math ^_^)

Now I'm interested in writing a real-time strategy game, similar to starcraft and command and conquer. I am confident in coding good macro AI (build orders, unit production, etc), but I am curious as to the best way for movement is. In a game, you select a unit (hehe gluUnProject ftw) then tell it to move/attack a certain location. What is the best way to do this? Here are my thoughts, any input is appreciated:

1. Check the line between pos and dest for obstructions
2. Flood-fill the obstruction to get all the coords of the obstructing object
3. Move pos around the end of obstruction that will result in the least distance travelled
4. Store this position in a waypoint array
5. Rinse and repeat until pos is as close to dest as possible
6. Move pos to each point in the waypoint array

I'm thinking that it should test ~10 different routes and determine which one's the fastest;
vector<vector<waypoint>> routes;

float minDistance=10000;int minIndex=-1;
for(i=0;i<routes.size;i++)
{
if(distance(routes.at(i))<minDistance)
{
minDistance = distance(routes.at(i));
minIndex=i;
}
}

etc.

Any ideas or links to tutorials on this subject are greatly appreciated :D
Advertisement
Uh... or A* pathfinding?

Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

This topic is closed to new replies.

Advertisement