hello there. I need to make a simple ai which triggers an event when it is near a specific model or the player.
here is the code for the ai of the cars.
function viol_func()
{
......blah blah
}
action FollowPath()
{
my.emask |= ENABLE_IMPACT;
my.event = viol_func;
reset(my,PASSABLE);
var temp;
// attach entity to nearest path
result = path_scan(me,my.x,my.pan,vector(360,180,1000));
if (result == 0) { wait(-10);} // no path found
my.skill1 = 1 ; //start with first node
path_getnode(my,my.skill1,my.skill2,NULL);
while(1) {
// close to node => get position of next node
my.skill4 = my.z;
if(vec_dist(my.skill2,my.x) < 16) {
my.skill1 = path_nextnode(my,my.skill1, 1);
path_getnode(my,my.skill1,my.skill2,NULL);
}
// turn to next node
vec_diff(my.skill5,my.skill2,my.x);
vec_to_angle(my.skill8,my.skill5);
my.pan += clamp(ang(my.skill8-my.pan)*0.50,-5,5)*time_step;
c_move(me,vector(aispeed *time_step,0,0),nullvector,GLIDE | IGNORE_PASSABLE | IGNORE_YOU);
if (my.skill1 == 0)
{
wait(-3);
aispeed = 5;
result = path_scan(me,my.x,my.pan,vector(360,180,1000));
// attach entity to nearest path
if (result == 0) { aispeed = 0;} // no path found
temp = path_scannode(my, 1);
my.skill1 = temp ; //start with first node
path_getnode(my,my.skill1,my.skill2,NULL);
}
if (my.skill1 > 3)
{
aispeed = 15;
}
wait(1);
}
}
action CarInit()
{
player = me;
c_setminmax(my);
my.flags |= ZNEAR;
// build a car and wait til all wheels are ready
ChassisInit();
my.material = mat_metal;
while (wheelCounter<4) { wait(1); }
snd_stop(engine_wav);
UpdateSpeed(); // update rear wheel speed (continuous)
SpeedControl();// change speed (continuous)
SteerControl();// change heading (continuous)
}
the code above can trigger an event in impact but I need to make it work on range.
an example is when the ai car is near the player the ai car will slow down or horn the player.
btw I used the car physics sample...
thanks.
Last edited by jpxtreme; 01/24/11 11:20.