add triggers
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
local tsf = entity.transform
|
||||
local body = entity.rigidbody
|
||||
|
||||
inair = true
|
||||
ready = false
|
||||
|
||||
function on_grounded(force)
|
||||
tsf:set_rot(mat4.rotate({0, 1, 0}, math.random()*360))
|
||||
inair = false
|
||||
ready = true
|
||||
end
|
||||
|
||||
function on_fall()
|
||||
inair = true
|
||||
end
|
||||
|
||||
function on_trigger_enter(index, oid)
|
||||
if ready then
|
||||
entity:despawn()
|
||||
end
|
||||
end
|
||||
|
||||
function on_update()
|
||||
if inair then
|
||||
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
|
||||
end
|
||||
@@ -1,23 +0,0 @@
|
||||
inair = true
|
||||
|
||||
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
|
||||
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
|
||||
@@ -3,15 +3,15 @@ local DROP_INIT_VEL = {0, 3, 0}
|
||||
|
||||
function on_hud_open()
|
||||
input.add_callback("player.drop", function ()
|
||||
for i=1,5 do
|
||||
for i=1,80 do
|
||||
local pid = hud.get_player()
|
||||
local pvel = {player.get_vel(pid)}
|
||||
local ppos = vec3.add({player.get_pos(pid)}, {0, 0.7, 0})
|
||||
local throw_force = vec3.mul(vec3.add(player.get_dir(pid),
|
||||
{
|
||||
math.random() - 0.5,
|
||||
math.random() - 0.5,
|
||||
math.random() - 0.5
|
||||
(math.random() - 0.5) * 5,
|
||||
(math.random() - 0.5) * 5,
|
||||
(math.random() - 0.5) * 5
|
||||
}), DROP_FORCE)
|
||||
|
||||
local drop = entity.spawn("base:drop", ppos)
|
||||
|
||||
Reference in New Issue
Block a user