mirror of
https://github.com/luanti-org/minetest_game.git
synced 2025-06-06 05:44:26 -04:00
Smooth boat turning to reach player yaw as he accelerates forward
This commit is contained in:
parent
abf0ca9c7e
commit
00b1b38ff0
1 changed files with 21 additions and 15 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
local pi = math.pi
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Helper functions
|
-- Helper functions
|
||||||
--
|
--
|
||||||
|
@ -9,10 +11,12 @@ end
|
||||||
|
|
||||||
|
|
||||||
local function get_sign(i)
|
local function get_sign(i)
|
||||||
if i == 0 then
|
if i < 0 then
|
||||||
return 0
|
return -1
|
||||||
|
elseif i > 0 then
|
||||||
|
return 1
|
||||||
else
|
else
|
||||||
return i / math.abs(i)
|
return 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -55,7 +59,7 @@ function boat.on_rightclick(self, clicker)
|
||||||
self.driver = nil
|
self.driver = nil
|
||||||
clicker:set_detach()
|
clicker:set_detach()
|
||||||
default.player_attached[name] = false
|
default.player_attached[name] = false
|
||||||
default.player_set_animation(clicker, "stand" , 30)
|
default.player_set_animation(clicker, "stand", 30)
|
||||||
local pos = clicker:getpos()
|
local pos = clicker:getpos()
|
||||||
pos = {x = pos.x, y = pos.y + 0.2, z = pos.z}
|
pos = {x = pos.x, y = pos.y + 0.2, z = pos.z}
|
||||||
minetest.after(0.1, function()
|
minetest.after(0.1, function()
|
||||||
|
@ -77,7 +81,7 @@ function boat.on_rightclick(self, clicker)
|
||||||
minetest.after(0.2, function()
|
minetest.after(0.2, function()
|
||||||
default.player_set_animation(clicker, "sit" , 30)
|
default.player_set_animation(clicker, "sit" , 30)
|
||||||
end)
|
end)
|
||||||
self.object:setyaw(clicker:get_look_yaw() - math.pi / 2)
|
self.object:setyaw(clicker:get_look_yaw() - pi / 2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -128,24 +132,26 @@ function boat.on_step(self, dtime)
|
||||||
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:getyaw()
|
local yaw = self.object:getyaw()
|
||||||
|
local delta = 0
|
||||||
if ctrl.up then
|
if ctrl.up then
|
||||||
self.v = self.v + 0.1
|
self.v = self.v + 0.1
|
||||||
|
local d = self.driver:get_look_yaw() - pi / 2 - yaw
|
||||||
|
d = d - math.floor((1 + d / pi) / 2) * pi * 2
|
||||||
|
delta = delta + d * self.v * dtime / 10
|
||||||
elseif ctrl.down then
|
elseif ctrl.down then
|
||||||
self.v = self.v - 0.1
|
self.v = self.v - 0.1
|
||||||
end
|
end
|
||||||
if ctrl.left then
|
if ctrl.left then
|
||||||
if self.v < 0 then
|
delta = delta + (1 + dtime) * 0.03
|
||||||
self.object:setyaw(yaw - (1 + dtime) * 0.03)
|
|
||||||
else
|
|
||||||
self.object:setyaw(yaw + (1 + dtime) * 0.03)
|
|
||||||
end
|
|
||||||
elseif ctrl.right then
|
elseif ctrl.right then
|
||||||
if self.v < 0 then
|
delta = delta - (1 + dtime) * 0.03
|
||||||
self.object:setyaw(yaw + (1 + dtime) * 0.03)
|
|
||||||
else
|
|
||||||
self.object:setyaw(yaw - (1 + dtime) * 0.03)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
if self.v < 0 then
|
||||||
|
yaw = yaw - delta
|
||||||
|
else
|
||||||
|
yaw = yaw + delta
|
||||||
|
end
|
||||||
|
self.object:setyaw(yaw)
|
||||||
end
|
end
|
||||||
local velo = self.object:getvelocity()
|
local velo = self.object:getvelocity()
|
||||||
if self.v == 0 and velo.x == 0 and velo.y == 0 and velo.z == 0 then
|
if self.v == 0 and velo.x == 0 and velo.y == 0 and velo.z == 0 then
|
||||||
|
|
Loading…
Add table
Reference in a new issue