From c50224e05cfc7a37b9181565024c972446a720ca Mon Sep 17 00:00:00 2001 From: Pedro Gimeno Date: Sat, 6 Apr 2019 13:38:00 +0200 Subject: [PATCH] Set wagon pitch on slopes --- advtrains/wagons.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/advtrains/wagons.lua b/advtrains/wagons.lua index 27df95e..5b15c70 100644 --- a/advtrains/wagons.lua +++ b/advtrains/wagons.lua @@ -503,7 +503,16 @@ function wagon:on_step(dtime) self.turning = false end - self.object:setyaw(yaw) + if self.object.set_rotation then + local pitch = math.atan2(vdir.y, math.hypot(vdir.x, vdir.z)) + if data.wagon_flipped then + pitch = -pitch + end + self.object:set_rotation({x=pitch, y=yaw, z=0}) + else + self.object:setyaw(yaw) + end + self.updatepct_timer=2 if self.update_animation then self:update_animation(train.velocity, self.old_velocity)