From 8beacdc5085c0a88e0fe8a1983b5f7f9874183a0 Mon Sep 17 00:00:00 2001 From: orwell96 Date: Thu, 24 Feb 2022 22:04:39 +0100 Subject: Fix new wagon positioning when wheel positions are asymmetric, and remove leftover train.debug --- advtrains/wagons.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/advtrains/wagons.lua b/advtrains/wagons.lua index d353d53..fe1a0f8 100644 --- a/advtrains/wagons.lua +++ b/advtrains/wagons.lua @@ -427,7 +427,9 @@ function wagon:on_step(dtime) local pos2 = advtrains.path_get_interpolated(train, index2) npos = advtrains.path_get(train, atfloor(index)) -- need npos just for node loaded check -- calculate center of 2 positions and vdir vector - pos = advtrains.pos_median(pos1, pos2) + -- if wheel positions are asymmetric, needs to weight by the difference! + local fact = self.wheel_positions[1] / (self.wheel_positions[1]-self.wheel_positions[2]) + pos = {x=pos1.x-(pos1.x-pos2.x)*fact, y=pos1.y-(pos1.y-pos2.y)*fact, z=pos1.z-(pos1.z-pos2.z)*fact} if data.wagon_flipped then vdir = vector.normalize(vector.subtract(pos2, pos1)) else @@ -520,7 +522,6 @@ function wagon:on_step(dtime) if data.wagon_flipped then oyaw = yaw + math.pi end - train.debug = "yaw "..yaw.." oyaw "..oyaw.." flip "..(data.wagon_flipped and "yes" or "no") --FIX: use index of the wagon, not of the train. local velocity = train.velocity * advtrains.global_slowdown -- cgit v1.2.3