forked from VoxeLibre/VoxeLibre
Boats: Allow very slow movement on ground
This commit is contained in:
parent
b3bbf38fd7
commit
3cba55703a
|
@ -34,6 +34,7 @@ local boat_visual_size = {x = 3, y = 3}
|
||||||
local driver_visual_size = { x = 1/boat_visual_size.x, y = 1/boat_visual_size.y }
|
local driver_visual_size = { x = 1/boat_visual_size.x, y = 1/boat_visual_size.y }
|
||||||
local paddling_speed = 22
|
local paddling_speed = 22
|
||||||
local boat_y_offset = 0.35
|
local boat_y_offset = 0.35
|
||||||
|
local boat_y_offset_ground = boat_y_offset + 0.6
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Boat entity
|
-- Boat entity
|
||||||
|
@ -145,12 +146,21 @@ end
|
||||||
|
|
||||||
function boat.on_step(self, dtime)
|
function boat.on_step(self, dtime)
|
||||||
self._v = get_v(self.object:get_velocity()) * get_sign(self._v)
|
self._v = get_v(self.object:get_velocity()) * get_sign(self._v)
|
||||||
|
local in_water = true
|
||||||
|
local v_factor = 1
|
||||||
|
local v_slowdown = 0.02
|
||||||
|
local p = self.object:get_pos()
|
||||||
|
if not is_water({x=p.x, y=p.y-boat_y_offset, z=p.z}) then
|
||||||
|
in_water = false
|
||||||
|
v_factor = 0.405
|
||||||
|
v_slowdown = 0.04
|
||||||
|
end
|
||||||
if self._driver then
|
if self._driver then
|
||||||
local ctrl = self._driver:get_player_control()
|
local ctrl = self._driver:get_player_control()
|
||||||
local yaw = self.object:get_yaw()
|
local yaw = self.object:get_yaw()
|
||||||
if ctrl.up then
|
if ctrl.up then
|
||||||
-- Forwards
|
-- Forwards
|
||||||
self._v = self._v + 0.1
|
self._v = self._v + 0.1 * v_factor
|
||||||
|
|
||||||
-- Paddling animation
|
-- Paddling animation
|
||||||
if self._animation ~= 1 then
|
if self._animation ~= 1 then
|
||||||
|
@ -159,7 +169,7 @@ function boat.on_step(self, dtime)
|
||||||
end
|
end
|
||||||
elseif ctrl.down then
|
elseif ctrl.down then
|
||||||
-- Backwards
|
-- Backwards
|
||||||
self._v = self._v - 0.1
|
self._v = self._v - 0.1 * v_factor
|
||||||
|
|
||||||
-- Paddling animation, reversed
|
-- Paddling animation, reversed
|
||||||
if self._animation ~= -1 then
|
if self._animation ~= -1 then
|
||||||
|
@ -175,15 +185,15 @@ function boat.on_step(self, dtime)
|
||||||
end
|
end
|
||||||
if ctrl.left then
|
if ctrl.left then
|
||||||
if self._v < 0 then
|
if self._v < 0 then
|
||||||
self.object:set_yaw(yaw - (1 + dtime) * 0.03)
|
self.object:set_yaw(yaw - (1 + dtime) * 0.03 * v_factor)
|
||||||
else
|
else
|
||||||
self.object:set_yaw(yaw + (1 + dtime) * 0.03)
|
self.object:set_yaw(yaw + (1 + dtime) * 0.03 * v_factor)
|
||||||
end
|
end
|
||||||
elseif ctrl.right then
|
elseif ctrl.right then
|
||||||
if self._v < 0 then
|
if self._v < 0 then
|
||||||
self.object:set_yaw(yaw + (1 + dtime) * 0.03)
|
self.object:set_yaw(yaw + (1 + dtime) * 0.03 * v_factor)
|
||||||
else
|
else
|
||||||
self.object:set_yaw(yaw - (1 + dtime) * 0.03)
|
self.object:set_yaw(yaw - (1 + dtime) * 0.03 * v_factor)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
@ -193,13 +203,11 @@ function boat.on_step(self, dtime)
|
||||||
self._animation = 0
|
self._animation = 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local velo = self.object:get_velocity()
|
|
||||||
if self._v == 0 and velo.x == 0 and velo.y == 0 and velo.z == 0 then
|
|
||||||
self.object:set_pos(self.object:get_pos())
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local s = get_sign(self._v)
|
local s = get_sign(self._v)
|
||||||
self._v = self._v - 0.02 * s
|
if not in_water and math.abs(self._v) > 0.1 then
|
||||||
|
v_slowdown = v_slowdown * 5
|
||||||
|
end
|
||||||
|
self._v = self._v - v_slowdown * s
|
||||||
if s ~= get_sign(self._v) then
|
if s ~= get_sign(self._v) then
|
||||||
self.object:set_velocity({x = 0, y = 0, z = 0})
|
self.object:set_velocity({x = 0, y = 0, z = 0})
|
||||||
self._v = 0
|
self._v = 0
|
||||||
|
@ -209,18 +217,12 @@ function boat.on_step(self, dtime)
|
||||||
self._v = 5 * get_sign(self._v)
|
self._v = 5 * get_sign(self._v)
|
||||||
end
|
end
|
||||||
|
|
||||||
local p = self.object:get_pos()
|
|
||||||
p.y = p.y - boat_y_offset
|
p.y = p.y - boat_y_offset
|
||||||
local new_velo
|
local new_velo
|
||||||
local new_acce = {x = 0, y = 0, z = 0}
|
local new_acce = {x = 0, y = 0, z = 0}
|
||||||
if not is_water(p) then
|
if not is_water(p) then
|
||||||
local nodedef = minetest.registered_nodes[minetest.get_node(p).name]
|
local nodedef = minetest.registered_nodes[minetest.get_node(p).name]
|
||||||
if (not nodedef) or nodedef.walkable then
|
new_acce = {x = 0, y = -9.8, z = 0}
|
||||||
self._v = 0
|
|
||||||
new_acce = {x = 0, y = 1, z = 0}
|
|
||||||
else
|
|
||||||
new_acce = {x = 0, y = -9.8, z = 0}
|
|
||||||
end
|
|
||||||
new_velo = get_velocity(self._v, self.object:get_yaw(),
|
new_velo = get_velocity(self._v, self.object:get_yaw(),
|
||||||
self.object:get_velocity().y)
|
self.object:get_velocity().y)
|
||||||
self.object:set_pos(self.object:get_pos())
|
self.object:set_pos(self.object:get_pos())
|
||||||
|
@ -302,10 +304,11 @@ for b=1, #boat_ids do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if not is_water(pointed_thing.under) then
|
if is_water(pointed_thing.under) then
|
||||||
return
|
pointed_thing.under.y = pointed_thing.under.y + boat_y_offset
|
||||||
|
else
|
||||||
|
pointed_thing.under.y = pointed_thing.under.y + boat_y_offset_ground
|
||||||
end
|
end
|
||||||
pointed_thing.under.y = pointed_thing.under.y + boat_y_offset
|
|
||||||
local boat = minetest.add_entity(pointed_thing.under, "mcl_boats:boat")
|
local boat = minetest.add_entity(pointed_thing.under, "mcl_boats:boat")
|
||||||
boat:get_luaentity()._itemstring = itemstring
|
boat:get_luaentity()._itemstring = itemstring
|
||||||
boat:set_properties({textures = { "mcl_boats_texture_"..images[b].."_boat.png" }})
|
boat:set_properties({textures = { "mcl_boats_texture_"..images[b].."_boat.png" }})
|
||||||
|
|
Loading…
Reference in New Issue