Preserve the player's looking direction

Contributed by @gpcf
master
orwell96 2017-11-23 19:59:21 +01:00 committed by GitHub
parent d78d07589d
commit 7ea41df5d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 0 deletions

View File

@ -477,6 +477,28 @@ function wagon:on_step(dtime)
self.object:setpos(actual_pos)
self.object:setvelocity(velocityvec)
self.object:setacceleration(accelerationvec)
if #self.seats > 0 and self.old_yaw ~= yaw then
if not self.player_yaw then
self.player_yaw = {}
end
for _,name in pairs(self.seatp) do
local p = minetest.get_player_by_name(name)
if p then
if not self.turning then
-- save player looking direction offset
self.player_yaw[name] = p:get_look_horizontal()-self.old_yaw
end
-- set player looking direction using calculated offset
p:set_look_horizontal(self.player_yaw[name]+yaw)
end
end
self.turning = true
elseif self.old_yaw == yaw then
-- train is no longer turning
self.turning = false
end
self.object:setyaw(yaw)
self.updatepct_timer=2
if self.update_animation then