aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authororwell96 <mono96.mml@gmail.com>2017-11-23 19:59:21 +0100
committerGitHub <noreply@github.com>2017-11-23 19:59:21 +0100
commit7ea41df5d9e269a35ffcd64b90c7a21ec8012a22 (patch)
tree82e0a5ad61900893cade576148fa0972eef18d26
parentd78d07589d31db62167eafafb36b9e8c0468c6d1 (diff)
downloadadvtrains-7ea41df5d9e269a35ffcd64b90c7a21ec8012a22.tar.gz
advtrains-7ea41df5d9e269a35ffcd64b90c7a21ec8012a22.tar.bz2
advtrains-7ea41df5d9e269a35ffcd64b90c7a21ec8012a22.zip
Preserve the player's looking direction
Contributed by @gpcf
-rw-r--r--advtrains/wagons.lua22
1 files changed, 22 insertions, 0 deletions
diff --git a/advtrains/wagons.lua b/advtrains/wagons.lua
index 8e3dd8d..3892813 100644
--- a/advtrains/wagons.lua
+++ b/advtrains/wagons.lua
@@ -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