• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Help with image angle!

B

Big_Macca_101

Guest
Hi guys, I'm working on a top down space exploration game and when using the code bellow I get weird behaviour as seen in the GIF.

Code:
Code:
dir = point_direction(x, y, device_mouse_x(0), device_mouse_y(0));

if(round(dir) != round(image_angle)) {
    image_angle = lerp(image_angle, dir, 0.05);
}
Current behaviour:


Could someone help me change my code to make it so the ship always lerp's towards the mouse cursor instead of having to do a full rotation the other way!

Thanks!
 
T

TDSrock

Guest
The key issue is what point_direction returns.
A value between 0 and 360.
So I see two fixes possible.
Have it so that dir will add the difference in angle compared to current distance so that dir can become any number.
Or
Have it so that when dir suddenly shoots to 360 or 0 that there is some kind of compensation.

Of these two solutions I would head into the first one as it seems the most straightforward.
The basics go something like this: (Note I will provide this in a spoiler, I hope you try to look into the solution before looking into my code)
Code:
last_dir = cur_dir;//set last_dir to be previouse frame's dir, be sure to have both these values in your create event!
cur_dir = point_direction(x, y, device_mouse_x(0), device_mouse_y(0));

dir_dif = last_dir - cur_dir;

rotation += dir_dif;

if(round(rotation) != round(image_angle)) {
    image_angle = lerp(image_angle, rotation, 0.05);
}
//ensure that in the create event the values dir_dif = 0, last_dir = 0, cur_dir = 0 and rotation = 0;
Note that this is just theoretical and it may show some odd behavior when the mouse goes out of focus. Maybe compare rotation and cur_dir with modulo to catch the behavior(if it even appears)?
 
T

TimothyAllen

Guest
Hi guys, I'm working on a top down space exploration game and when using the code bellow I get weird behaviour as seen in the GIF.

Code:
Code:
dir = point_direction(x, y, device_mouse_x(0), device_mouse_y(0));

if(round(dir) != round(image_angle)) {
    image_angle = lerp(image_angle, dir, 0.05);
}
Current behaviour:


Could someone help me change my code to make it so the ship always lerp's towards the mouse cursor instead of having to do a full rotation the other way!

Thanks!
Guy asking this question a couple of days ago. Two working codes:
https://forum.yoyogames.com/index.php?threads/problem-with-lerp-and-angle.4731/#post-36042
 
Top