Rotate toward an object with collision ....

Posted By: bk9iq

Rotate toward an object with collision .... - 01/18/11 02:10

Hello everybody,
This is probably the most noob question ever but I still can't get it to work...
I am using this to make my enemy rotate toward the player however I want to add collision so that it doesn't go through the walls when turning::

Quote:
vec_to_angle(my.pan,vec_diff(NULL,player.x,my.x));



I tried c_rotate but didn't work:
Quote:
vec_to_angle(pan_enemy.pan,vec_diff(NULL,player.x,my.x));
c_rotate(my,pan_enemy.pan, NULL);


Any ideas please...
Posted By: Superku

Re: Rotate toward an object with collision .... - 01/18/11 02:29

Quote:
I tried c_rotate but didn't work

Please... always tell what did not work and why you did not like the result...

c_rotate(my,pan_enemy.pan, NULL);
will add the pan_enemy angles to the current my.pan orientation. You would have to calculate the angle difference (f.i. with ang_diff) or do it as follows:

c_rotate(my,vector(ang(pan_enemy.pan-my.pan)*time_step,0,0), NULL); //or remove time_step, depends on your situation
Posted By: bk9iq

Re: Rotate toward an object with collision .... - 01/18/11 03:45

Thanks Superku for the reply .... I tried that and It makes the enemy changes its pan only and I couldn't make it change its Tilt .... (( However doesn't c_rotate take angle rather than vector... why do u use vector?? ))
I tried using ent_turnto which is included in entmove.c in A8 however it also makes the enemy rotate with no collision detection thus useless for my case...



Posted By: Superku

Re: Rotate toward an object with collision .... - 01/18/11 15:14

The functions usually work with both ANGLE and VECTOR.

c_rotate(my,vector(ang(pan_enemy.pan-my.pan)*time_step,ang(pan_enemy.tilt-my.tilt)*time_step,0), NULL);

Or use ang_diff and the like, as I've already suggested.
Posted By: bk9iq

Re: Rotate toward an object with collision .... - 01/20/11 04:09

Thanks again Superku...
I am sorry for asking too much but it still doesn't work... the enemy which is a turret gets stuck and points randomly and not toward my player ....
here's what I am using exactly ::

Code:
action turret()
{
	ANGLE pan_enemy;
	c_setminmax(me);
	my.Health = 100;
	while(my.Health>0)
	{
		vec_to_angle(pan_enemy.pan,vec_diff(NULL,player.x,my.x));
		c_rotate(my,vector(ang(pan_enemy.pan-my.pan)*time_step,ang(pan_enemy.tilt-my.tilt)*time_step,0), NULL);
		wait(1);
		
	}
	
}



I don't know what is going wrong!!!
© 2024 lite-C Forums