Tight arch

Posted By: Logitek

Tight arch - 03/07/16 13:15

Hi, I use this code to make a smooth rotation for the enemy:

Quote:

vec_diff(temp_dir, camera.x, my.x);
vec_to_angle(offset_angle, temp_dir);
my.pan += ang(offset_angle.pan - my.pan) * 0.2 * time_step;


The enemy rotates smoothly to the camera, after detecting the player.

This is fine. But, if the enemy is currently going on a path or only straight forward, the enemy is rotating to the player while walking in a bow.

This is also fine. But this arch is not tight enough. Is it possible to make that arch or bow tighter?

I will try to describe it with a little sketch.

P = player
E = Enemy

1: Enemy is on path or straight forward, walking away from player.

|
|
E


P


2: Enemy has detected player and is turning with the quoted code. You can see the way of the enemy on the line. (Please forget the points. They show only the distance) Watch only the line.

.___
/....\
E....|

P

But this way/arch is too wide.

It should be like:
.__
/..\
E..|

P

The turning bow is tighter.



Any idea to reach this goal?

Thanks.
Posted By: Superku

Re: Tight arch - 03/07/16 13:23

Something like

my.pan += clamp(ang(offset_angle.pan - my.pan) * 0.5, -25*time_step,25*time_step);

maybe? If the last bit of turning should be smoother again, take the "time_step" out of the clamp instruction again and put it at the end of the line.

Alternatively or on top of that, you can separate move direction and the actual pan value. I do that every now and then, too, when I for example want to move an enemy plane on a rather tight path but still want it to look smooth. Something like this:

my.skill10 += clamp(ang(offset_angle.pan - my.skill10),-25,25)*time_step;
my.pan += ang(my.skill10-my.pan)*0.2*time_step; // or some other clamp thingy too
vec_set(temp,vector(15*time_step,0,0)); // the move speed
vec_rotate(temp,vector(my.skill10,0,0));
c_move(me,nullvector,temp,...);
Posted By: Logitek

Re: Tight arch - 03/07/16 13:40

Hi, okay thank you for the fast reply and the hints. I will try that and will leave a feedback laugh
Posted By: Logitek

Re: Tight arch - 03/07/16 16:51

Thank you, it is working fine!
Posted By: Superku

Re: Tight arch - 03/07/16 17:28

Good, and you are welcome!
© 2024 lite-C Forums