how do i increase the rotation speed of this code?

S

Sitruc

Guest
cant figure out how to increase the speed at which the image rotates towards the mouse. Thanks!

var aimed_angle = round(point_direction(-x,-y,-mouse_x,-mouse_y));
image_angle += sign( angle_difference(aimed_angle, image_angle) );
 

obscene

Member
image_angle += sign ....

sign will return 1 or -1, so that's the maximum speed it will move at. You could multiply it by 2 or 3 to increase the speed. The side effect is that by increasing in larger numbers it could skip past the correct angle and then jitter back and forth. You'll see if you try it. So you'll have to work on some kind of fix for that... for example...

if abs(angle_difference(etc)) < the_speed_you_are_using image_angle=aimed_angle
 

hippyman

Member
Code:
var turnSpeed =  5;
var angDiff = angle_difference(image_angle,desiredAngle);
var absDiff = abs(angDiff);
image_angle -= sign(angDiff) * min(absDiff,turnSpeed);
This should allow you to assign any speed and it will always lock onto the desired angle
 
Top