add entity event: on_fall

This commit is contained in:
MihailRis
2024-06-30 00:32:02 +03:00
parent 3946119a67
commit 50c714692a
5 changed files with 36 additions and 7 deletions
+14 -2
View File
@@ -1,11 +1,23 @@
inair = true
function on_grounded()
function on_grounded(force)
entity.transform:set_rot(mat4.rotate({0, 1, 0}, math.random()*360))
inair = false
end
function on_fall()
inair = true
end
function on_update()
local tsf = entity.transform
local body = entity.rigidbody
if inair then
entity.transform:set_rot(mat4.rotate(entity.transform:get_rot(), {0, 1, 0}, math.random()*32))
tsf:set_rot(mat4.rotate(tsf:get_rot(), {0, 1, 0}, math.random()*12))
tsf:set_rot(mat4.rotate(tsf:get_rot(), {0, 0, 1}, math.random()*12))
end
local dir = vec3.sub({player.get_pos(hud.get_player())}, tsf:get_pos())
vec3.normalize(dir, dir)
vec3.mul(dir, time.delta()*50.0, dir)
--body:set_vel(vec3.add(rigidbody:get_vel(), dir))
end