-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMolang.lua
More file actions
98 lines (90 loc) · 1.94 KB
/
Copy pathMolang.lua
File metadata and controls
98 lines (90 loc) · 1.94 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
-- Implementing math.mod for molang compatibility
-- Modified by ynrie to use native C functions
function math.mod(x, y)
return x % y
end
math.random_integer = math.random
-- Native C trig calls avoid Lua instruction overhead. q.anim_time is
-- pre-scaled by DEG_TO_RAD so expressions like Math.sin(time * 360) produce
-- the correct oscillation frequency despite radians-vs-degrees mismatch.
Math = Math or {}
Math.sin = math.sin
Math.cos = math.cos
local DEG_TO_RAD = math.pi / 180
q = { anim_time = 0 }
local TICK_SECONDS = 0.05
local anim_time = 0
local rot = vec(0, 0, 0)
local last_rot = rot
local rot_change = vec(0, 0, 0)
local last_rot_change = vec(0, 0, 0)
local friction = 0.6
function events.tick()
anim_time = anim_time + TICK_SECONDS
q.anim_time = anim_time * DEG_TO_RAD
last_rot = rot
rot = (player:getRot().xy_ + 180) % 360 - 180
last_rot_change = rot_change
rot_acc = math.shortAngle(rot, last_rot) * -20
rot_change = rot_change + rot_acc
rot_change = rot_change * friction
end
function events.render(delta)
local d = delta or 0
q.anim_time = (anim_time + (TICK_SECONDS * d)) * DEG_TO_RAD
rot_delta = math.lerp(last_rot_change, rot_change, d)
end
q.r = {
velocity_x = function()
return 0
end,
velocity_y = function()
return 0
end,
velocity_z = function()
return 0
end,
yaw_change = function()
return math.clamp(rot_delta.y / 140, -1, 1)
end,
pitch_change = function()
return math.clamp(rot_delta.x / 90, -1, 1) * -1
end,
roll_change = function()
return 0
end,
speed = function()
return 0
end,
velocity_right = function()
return 0
end,
velocity_left = function()
return 0
end,
velocity_forward = function()
return 0
end,
velocity_up = function()
return 0
end,
yaw = function()
return 0
end,
pitch = function()
return 0
end,
roll = function()
return 0
end,
input_right = function()
return 0
end,
input_forward = function()
return 0
end,
input_up = function()
return 0
end
}
query = q