-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscr_smooth_turn.gml
56 lines (54 loc) · 1.09 KB
/
scr_smooth_turn.gml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
///scr_smooth_turn(current, target, turn_speed)
//var target_angle = point_direction(x, y, mouse_x, mouse_y);
//image_angle = scr_smoothTurn(image_angle, target_angle, 4);
var tempdir;
var angle = argument0;
var target_angle = argument1;
var turn_speed = argument2;
var diff = abs(target_angle-angle);
if (diff > 180)
{
if (target_angle > 180)
{
tempdir = target_angle - 360;
if (abs(tempdir-angle ) > turn_speed)
{
angle -= turn_speed;
}
else
{
angle = target_angle;
}
}
else
{
tempdir = target_angle + 360;
if (abs(tempdir-angle) > turn_speed)
{
angle += turn_speed;
}
else
{
angle = target_angle;
}
}
}
else
{
if (diff > turn_speed)
{
if (target_angle > angle)
{
angle += turn_speed;
}
else
{
angle -= turn_speed;
}
}
else
{
angle = target_angle;
}
}
return angle;