I don't have much time so this is quick, this is the code I use, it works but it will need adapting for your needs:
function fnct_avoid_ai()
{
while(me != null)
{
my.avoid_left = 0;
my.avoid_right = 0;
if (my.task != 3 && my.task != 4 && my.task != 5)
{
// do 'antenna' trace 1
vec_set(temp, vector (-400,0,0));
vec_rotate (temp,vector(my.pan+160,0,0));
vec_add(temp, my.x);
//ent_create(ball, temp, act_ball);
result = c_trace(my.x,temp,IGNORE_ME|IGNORE_PASSABLE|IGNORE_PUSH); // do a trace and make result = to the found value
if (result > 0)
{
//my.pan += 4;
my.avoid_right = 1;
}
// do 'antenna' trace 2
vec_set(temp, vector (-400,0,0));
vec_rotate (temp,vector(my.pan+200,0,0)); // gets a vector for the point shown by the angle so that the 'antenna' sticks out
vec_add(temp, my.x);
//ent_create(ball, temp, act_ball);
result = c_trace(my.x,temp,IGNORE_ME|IGNORE_PASSABLE|IGNORE_PUSH); // do a trace and make result = to the found value
if (result > 0)
{
my.avoid_left = 1;
//my.pan -= 3;
}
}
if(my.avoid_right == 1)
{
my.pan += 4;
}
if(my.avoid_left == 1)
{
my.pan -= 4;
}
if(my.avoid_right == 1 && my.avoid_left == 1)
{
my.pan += 4;
}
wait(1);
}
}