<req> object avoidance

Posted By: PrenceOfDarkness

<req> object avoidance - 12/04/10 06:29

does anyone have any object avoidance code? something simple is fine. the aum ones still use c contant. could make it myself but donwant to remake it if it was all ready done
Posted By: painkiller

Re: <req> object avoidance - 12/04/10 11:21

Here it is, I adapted it some moths ago:

Code:
if(my.state==2) //chasing player
{
	if(c_trace(my.x, content_right, IGNORE_ME|IGNORE_PASSABLE|IGNORE_SPRITES)+c_trace(my.x, content_left, IGNORE_ME|IGNORE_PASSABLE|IGNORE_SPRITES)==0)
	{
		vec_set(temp_vec, player.x);  //turn smoothly to player
		vec_sub(temp_vec,my.x); 
		vec_to_angle(temp_angle, temp_vec);
		if(ang(temp_angle.pan - my.pan)<-2|ang(temp_angle.pan - my.pan)>2)	my.pan += sign(ang(temp_angle.pan - my.pan))*time_step*5;
	}
	vec_set(content_right, vector(50, -20, -15));
	vec_rotate(content_right, my.pan);
	vec_add(content_right, my.x);
	if(c_trace(my.x, content_right, IGNORE_ME|IGNORE_PASSABLE|IGNORE_SPRITES)!=0)
	{
		my.pan += 10 * time_step; // then rotate the enemy, allowing it to avoid the obstacle
	}
	vec_set(content_left, vector(50, 20, -15));
	vec_rotate(content_left, my.pan);
	vec_add(content_left, my.x);
	if(c_trace(my.x, content_left, IGNORE_ME|IGNORE_PASSABLE|IGNORE_SPRITES)!=0)
	{
		my.pan -= 10 * time_step; // then rotate the enemy, allowing it to avoid the obstacle
	}
	c_move (my, vector(10 * time_step, 0, 0), nullvector, GLIDE|IGNORE_PASSABLE);
	ent_animate(my, "run", my.animation_frame, ANM_CYCLE); // play the "run" animation
	my.animation_frame += 9 * time_step; // "9" controls the animation speed
	if(vec_dist(my.x, player.x)<500) //attack
	{
		my.state=3;
		my.animation_frame=0;
	}
	if(vec_dist(my.x, player.x)>2500) //stand
	{
		my.state=1;
		my.animation_frame=0;
	}
}


Posted By: PrenceOfDarkness

Re: <req> object avoidance - 12/04/10 23:14

thanks painkiller your a time saver!

btw if you add an if state you can save the computer from runnning two slow traces. maybe at the second if as well.
Posted By: 3run

Re: <req> object avoidance - 12/05/10 15:55

I'm having little problem with it, when I try to increase the turning speed, AI starts jerking.... How can I prevent that? laugh
I've tried to use 'ent_turnto' from A8's 'ent_move.c' library, but AI turns around its pan... May be that's because I try to use it with A7?
© 2024 lite-C Forums