Making One Object's image_angle Gradually 'Follow' Another Object's image_angle?

C

Cam Croft

Guest
I have a player object(oPlayer) with two gun objects, each centered on the player object. The image_angle of the first gun object(oGunNoDelay) always points towards the mouse position, and it works great for aiming.

I'd like to try something different with the second gun object(oGunAuto)...basically, I want to take the difference between oGunNoDelay.image_angle and oGunAuto.image_angle and use it to set oGunAuto's image_angle to be some % 'closer' to oGunNoDelay's image_angle each game step.

I know(for image_angle and direction) right is 0º, up is 90º, left is 180º and down is 270º...but I'm unsure how to use that to accomplish what I'm trying to accomplish.

Ideally, I'd like for oGunAuto to be smart enough to ease towards oGunNoDelay along the shortest 'path'...which feels like a pretty inapplicable term for a rotation. Ha.

Any choice bits of wisdom?
 
D

Danei

Guest
Subtract your target image_angle (oGunNoDelay) from the current image_angle of the gun that will move (oGunAuto) and call that n. If abs(n) >= 180, then image_angle should be incremented by sign(n) * (your_rotation_speed). if abs(n) < 180, increment it by -sign(n) * (your_rotation_speed).

Conceptually, this is supposing that your target angle is 0 and then looking at whether the other angle is greater or less than 0 (by the way, if you didn't know, negative angles just go around the circle clockwise, so -270º == 90º, -180º == 180º, and so forth), and then if the angle is acute, shrink it back down to zero; or if it's obtuse, just keep it going until it wraps back around. The actual angles involved barely matter; you just need to know whether to move the thing cw or ccw. Hope that helps / makes sense / is correct!
 
I

icuurd12b42

Guest
var adif = angle_difference(a1,a2);
a2+= median(-5,adif,5);
 
S

steveyg90

Guest
Interpolation...

Code:
image_angle=lerp(image_angle, direction, 1);
[code]
 
I

icuurd12b42

Guest
^ that is wrong because
1) .5 should be used
2) interpolate 359 with 0 and see where that takes you
 
Last edited by a moderator:
Top