GML Lerping shortest distance in a circle?

kamiyasi

Member
Here's my scenario. It's a twinstick shooter and right now I'm working on the keyboard controls. On a keyboard the player uses the arrow keys to aim. To emulate the smoothness of analog aiming, I am currently using lerp. For the most part this works fine, however, when lerping between a low degree such as 45 and a high degree such as 270, lerp obviously doesn't know that counting up past 360 is the shortest route. So what I would like to know is how I can make my aiming system prefer clockwise/counterclockwise, whichever is the smaller angle between points. Thank you. This is what I currently have.
Code:
var aimleft = keyboard_check(vk_left);
var aimup = keyboard_check(vk_up);
 var aimright = keyboard_check(vk_right);
 var aimdown = keyboard_check(vk_down);

///get gun pointing direction
    if (aimleft || aimup || aimright || aimdown)
    {
        pointing = lerp(pointing,( point_direction(0,0, (aimright*100) + (aimleft*-100), (aimdown*100) + (aimup*-100) )+dir-90 ),0.1);
    }
 
T

TimothyAllen

Guest
This has been solved quite a bit on the forums.

Look up angle_difference, it's now a built in function in GMS.
 
Top