At first, I took a simple approach: The AI checks if it's going to hit a stone. If it is, then checks if it's safe to turn to the left or to the right. If neither of the options is available, then it stops accelerating until reaching a small speed which makes the impact insignificant.
Unfortunately, that wasn't enough - it avoided some obstacles, but not all of them and even completely ignored other ones. Now I'm developing a more advanced algorithm which checks when and how the vehicles should behave based on the surrounding in the folowing one hundred meters or so. But I wonder should I continue and rewrite everything or it's better to improve the previous algorithm? I have no experience with AI at all.
Also if you want to know, here's the second algorithm:
The vehicle object upon reaching a x value which is dividable by 100 creates a test object. This test object calls a recursive script which checks is the current position collision free and if it is, creates another test object further away from the vehicle. When it reaches certain distance, the recursion stops and the AI deals with the gathered data.
Thanks in advance.
edit: the code:
Quote:
obstacle=checkforobstacle(x,y,distance*5,50);
flag=0;
if obstacle
{
if isleftturnpossible
{
flag=1;
if !checkforobstacle(x,y-30,distance*3,40){leftturn=1;rightturn=0;}
else flag=0;
}
else flag=0;
if isrightturnpossible&&!flag
{
if !checkforobstacle(x,y+30,distance*3,40){leftturn=0;rightturn=1;flag=1;}
else flag=0;
}
if !flag decelerates=1;
}
//script checkforobstacle
var xx,yy,g,uuu;
xx=argument0;//x coordinate to check
yy=argument1;//y coordinate to check
g=argument2;//the distance
if argument3==0 uuu=30;else uuu=argument3;//the width of the obstacle
if xx<control.tracklength
{
//the obstacle data is stored in an array
for(i=xx;i<xx+g;i+=50)
if control.obstaclex[ceil(i/100)]==1 //1 means it exists; 0 - it doesnt
if control.obstacley[ceil(i/100)]>yy-uuu&&control.obstacley[ceil(i/100)]<yy+uuu
{return 1;exit;}
return 0;
}
else return 0;
[Edited by - Plusekwal on August 9, 2010 6:33:29 AM]