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
🎉 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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement