# Beginning AI Programming

This topic is 2504 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

##### Share on other sites
Uh... or A* pathfinding?

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 11
• 9
• 9
• 43
• ### Forum Statistics

• Total Topics
634131
• Total Posts
3015719
×