Monday 28 March 2011

Traffic AI in C++




This an implementation of ambient AI traffic vehicles. This implementation is based on an article written by Joe Azdima on Gamasutra titled "AI Madness: Using AI to Bring Open-City Racing to Life". The following is the link to the article: http://www.gamasutra.com/view/feature/3106/ai_madness_using_ai_to_bring_.php?page=4 .

In this article the author describes how they developed certain types of AI for open world racing games such as Midtown madness 2 and Midnight Club (Azdima, J., 2001). The author discusses three different types of agents or AI which they developed for this game namely ambient traffic AI, opponent racer AI and pedestrians. However for this project I was mainly interested in attempting to reconstruct the ambient traffic AI. The entire project is made built in C++. For vehicle implementation I used Newton Game Dynamics phyiscs engine available at : http://newtondynamics.com/forum/downloads.php . For rendering I used an open source C++ rendering engine by the name of Irrlicht available at http://irrlicht.sourceforge.net/downloads.html . Both engines are much like the project itself C++ engines. The project makes extensive use of finite state machines. Basically all AI vehicles have states and they can only be in one state at any given time, depending on the kind of road they are in. For instance if the vehicle is driving along a straight road and there is no other vehicle close enough infront of it then that vehicle will be in a "Drive State" in which the vehivle will drive normally, how ever if the vehicle detects another vehicle infront of it will slow down(if it was travelling at a greater speed than the vehicle infront of it) and it will match the speed of the vehicle ahead going into a "Follow State". Other states included are states to handle traffic lights and stop signs. Something else that I implemented is steering behaviours(For more on this topic please read: http://www.red3d.com/cwr/steer/gdc99/). Basically within each state the vehicle can exihibit a variety of steering behaviours used to enable the AI vehicle to navigate the world. Essentialy the vehicle can have any number of behaviours enabled in its current state. The key behaviour which was implemented is the "Seek" behaviour. In this project waypoints are placed in each road and the vehicle "Seeks" out these points in order to determine where to go.