aboutsummaryrefslogtreecommitdiff
path: root/advtrains/wagons.lua
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2018-11-20 12:37:34 +0100
committerorwell96 <orwell@bleipb.de>2018-11-20 12:37:34 +0100
commit0f295ec4a94b25920d4ac1e107cfc469a70c8455 (patch)
tree4990155654c780e8fbb73596ea90945da67ce572 /advtrains/wagons.lua
parent4eb7531cc52b083b68673d4a8f9a8d271e60d37c (diff)
downloadadvtrains-0f295ec4a94b25920d4ac1e107cfc469a70c8455.tar.gz
advtrains-0f295ec4a94b25920d4ac1e107cfc469a70c8455.tar.bz2
advtrains-0f295ec4a94b25920d4ac1e107cfc469a70c8455.zip
Fix discouple positioning when wagon was just loaded
Diffstat (limited to 'advtrains/wagons.lua')
-rw-r--r--advtrains/wagons.lua48
1 files 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)