diff --git a/functions.lua b/functions.lua index 9bc3bb5..bcbbaa0 100644 --- a/functions.lua +++ b/functions.lua @@ -163,6 +163,11 @@ function boost_cart:pathfinder(pos_, expected_pos, old_dir, ctrl, pf_switch, rai local pf_dir = vector.new(old_dir) for i = 1, 3 do + if vector.equals(pf_pos, pos) then + -- Success! Cart moved on correctly + return true + end + pf_dir, pf_switch = boost_cart:get_rail_direction(pf_pos, pf_dir, ctrl, pf_switch, railtype) if vector.equals(pf_dir, {x=0, y=0, z=0}) then -- No way forwards @@ -170,10 +175,6 @@ function boost_cart:pathfinder(pos_, expected_pos, old_dir, ctrl, pf_switch, rai end pf_pos = vector.add(pf_pos, pf_dir) - if vector.equals(pf_pos, pos) then - -- Success! Cart moved on correctly - return true - end end -- Cart not found return false diff --git a/init.lua b/init.lua index 38b12c6..42ea48c 100644 --- a/init.lua +++ b/init.lua @@ -168,8 +168,8 @@ function boost_cart.cart:on_step(dtime) local pos = self.object:getpos() if self.old_pos and not self.punched then - local flo_pos = vector.floor(pos) - local flo_old = vector.floor(self.old_pos) + local flo_pos = vector.round(pos) + local flo_old = vector.round(self.old_pos) if vector.equals(flo_pos, flo_old) then -- Do not check one node multiple times return @@ -268,21 +268,23 @@ function boost_cart.cart:on_step(dtime) end if mesecon then - boost_cart:signal_detector_rail(vector.floor(pos)) + boost_cart:signal_detector_rail(vector.round(pos)) end - self.object:setacceleration(new_acc) - self.old_pos = vector.new(pos) - self.old_dir = vector.new(dir) - self.old_switch = last_switch - -- Limits for _,v in ipairs({"x","y","z"}) do if math.abs(vel[v]) > max_vel then vel[v] = boost_cart:get_sign(vel[v]) * max_vel + new_acc[v] = 0 update.vel = true end end + + self.object:setacceleration(new_acc) + self.old_pos = vector.new(pos) + self.old_dir = vector.new(dir) + self.old_switch = last_switch + if self.punched then -- Collect dropped items