Improve placement handling & audio bugfix
This commit is contained in:
parent
0282f6cb91
commit
5179779f49
22
hover.lua
22
hover.lua
@ -12,6 +12,7 @@ function hover:register_hovercraft(name, def)
|
|||||||
deceleration = def.deceleration,
|
deceleration = def.deceleration,
|
||||||
jump_velocity = def.jump_velocity,
|
jump_velocity = def.jump_velocity,
|
||||||
fall_velocity = def.fall_velocity,
|
fall_velocity = def.fall_velocity,
|
||||||
|
bounce = def.bounce,
|
||||||
player = nil,
|
player = nil,
|
||||||
sound = nil,
|
sound = nil,
|
||||||
thrust = 0,
|
thrust = 0,
|
||||||
@ -19,8 +20,21 @@ function hover:register_hovercraft(name, def)
|
|||||||
last_pos = {x=0, y=0, z=0},
|
last_pos = {x=0, y=0, z=0},
|
||||||
timer = 0,
|
timer = 0,
|
||||||
on_activate = function(self, staticdata, dtime_s)
|
on_activate = function(self, staticdata, dtime_s)
|
||||||
|
self.object:set_armor_groups({immortal=1})
|
||||||
self.object:set_animation({x=0, y=24}, 30)
|
self.object:set_animation({x=0, y=24}, 30)
|
||||||
end,
|
end,
|
||||||
|
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir)
|
||||||
|
if self.player then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if self.sound then
|
||||||
|
minetest.sound_stop(self.sound)
|
||||||
|
end
|
||||||
|
self.object:remove()
|
||||||
|
if puncher and puncher:is_player() then
|
||||||
|
puncher:get_inventory():add_item("main", name)
|
||||||
|
end
|
||||||
|
end,
|
||||||
on_rightclick = function(self, clicker)
|
on_rightclick = function(self, clicker)
|
||||||
if not clicker or not clicker:is_player() then
|
if not clicker or not clicker:is_player() then
|
||||||
return
|
return
|
||||||
@ -115,12 +129,12 @@ function hover:register_hovercraft(name, def)
|
|||||||
self.timer = 0
|
self.timer = 0
|
||||||
end
|
end
|
||||||
if self.last_pos.x == pos.x and math.abs(self.velocity.x) > 0.5 then
|
if self.last_pos.x == pos.x and math.abs(self.velocity.x) > 0.5 then
|
||||||
self.velocity.x = self.velocity.x * -0.8
|
self.velocity.x = self.velocity.x * (0 - self.bounce)
|
||||||
self.thrust = 0
|
self.thrust = 0
|
||||||
minetest.sound_play("hovercraft_bounce", {object = self.object})
|
minetest.sound_play("hovercraft_bounce", {object = self.object})
|
||||||
end
|
end
|
||||||
if self.last_pos.z == pos.z and math.abs(self.velocity.z) > 0.5 then
|
if self.last_pos.z == pos.z and math.abs(self.velocity.z) > 0.5 then
|
||||||
self.velocity.z = self.velocity.z * -0.8
|
self.velocity.z = self.velocity.z * (0 - self.bounce)
|
||||||
self.thrust = 0
|
self.thrust = 0
|
||||||
minetest.sound_play("hovercraft_bounce", {object = self.object})
|
minetest.sound_play("hovercraft_bounce", {object = self.object})
|
||||||
end
|
end
|
||||||
@ -159,8 +173,8 @@ function hover:register_hovercraft(name, def)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function hover:get_velocity(vx, vy, vz, yaw)
|
function hover:get_velocity(vx, vy, vz, yaw)
|
||||||
local x = math.cos(yaw)*vx+math.cos(math.pi/2+yaw)*vz
|
local x = math.cos(yaw) * vx + math.cos(math.pi / 2 + yaw) * vz
|
||||||
local z = math.sin(yaw)*vx+math.sin(math.pi/2+yaw)*vz
|
local z = math.sin(yaw) * vx + math.sin(math.pi / 2 + yaw) * vz
|
||||||
return {x=x, y=vy, z=z}
|
return {x=x, y=vy, z=z}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
2
init.lua
2
init.lua
@ -9,6 +9,7 @@ hover:register_hovercraft("hovercraft:hover_red" ,{
|
|||||||
deceleration = 0.025,
|
deceleration = 0.025,
|
||||||
jump_velocity = 4.0,
|
jump_velocity = 4.0,
|
||||||
fall_velocity = 1.0,
|
fall_velocity = 1.0,
|
||||||
|
bounce = 0.5,
|
||||||
})
|
})
|
||||||
|
|
||||||
hover:register_hovercraft("hovercraft:hover_blue" ,{
|
hover:register_hovercraft("hovercraft:hover_blue" ,{
|
||||||
@ -20,5 +21,6 @@ hover:register_hovercraft("hovercraft:hover_blue" ,{
|
|||||||
deceleration = 0.05,
|
deceleration = 0.05,
|
||||||
jump_velocity = 4,
|
jump_velocity = 4,
|
||||||
fall_velocity = 1,
|
fall_velocity = 1,
|
||||||
|
bounce = 0.8,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user