From 0f295ec4a94b25920d4ac1e107cfc469a70c8455 Mon Sep 17 00:00:00 2001 From: orwell96 Date: Tue, 20 Nov 2018 12:37:34 +0100 Subject: Fix discouple positioning when wagon was just loaded --- advtrains/wagons.lua | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/advtrains/wagons.lua b/advtrains/wagons.lua index c4210be..040400c 100644 --- a/advtrains/wagons.lua +++ b/advtrains/wagons.lua @@ -349,30 +349,6 @@ function wagon:on_step(dtime) end end - --DisCouple - if data.pos_in_trainparts and data.pos_in_trainparts>1 then - if train.velocity==0 then - if not self.discouple or not self.discouple.object:getyaw() then - atprint(self.id,"trying to spawn discouple") - local yaw = self.object:getyaw() - local flipsign=data.wagon_flipped and -1 or 1 - local dcpl_pos = vector.add(pos, {y=0, x=-math.sin(yaw)*self.wagon_span*flipsign, z=math.cos(yaw)*self.wagon_span*flipsign}) - local object=minetest.add_entity(dcpl_pos, "advtrains:discouple") - if object then - local le=object:get_luaentity() - le.wagon=self - --box is hidden when attached, so unuseful. - --object:set_attach(self.object, "", {x=0, y=0, z=self.wagon_span*10}, {x=0, y=0, z=0}) - self.discouple=le - end - end - else - if self.discouple and self.discouple.object:getyaw() then - self.discouple.object:remove() - atprint(self.id," removing discouple") - end - end - end --for path to be available. if not, skip step if not train.path or train.no_step then self.object:setvelocity({x=0, y=0, z=0}) @@ -448,6 +424,30 @@ function wagon:on_step(dtime) end end + --DisCouple + -- FIX: Need to do this after the yaw calculation + if data.pos_in_trainparts and data.pos_in_trainparts>1 then + if train.velocity==0 then + if not self.discouple or not self.discouple.object:getyaw() then + atprint(self.id,"trying to spawn discouple") + local dcpl_pos = vector.add(pos, {y=0, x=-math.sin(yaw)*self.wagon_span, z=math.cos(yaw)*self.wagon_span}) + local object=minetest.add_entity(dcpl_pos, "advtrains:discouple") + if object then + local le=object:get_luaentity() + le.wagon=self + --box is hidden when attached, so unuseful. + --object:set_attach(self.object, "", {x=0, y=0, z=self.wagon_span*10}, {x=0, y=0, z=0}) + self.discouple=le + end + end + else + if self.discouple and self.discouple.object:getyaw() then + self.discouple.object:remove() + atprint(self.id," removing discouple") + end + end + end + --FIX: use index of the wagon, not of the train. local velocity = train.velocity local acceleration = (train.acceleration or 0) -- cgit v1.2.3