From 5eb7321ab3f8046351d89aee31ea2c27a630a110 Mon Sep 17 00:00:00 2001 From: oilboi <47129783+oilboi@users.noreply.github.com> Date: Sun, 5 Jul 2020 20:51:19 -0400 Subject: [PATCH] Tune coupling collision detection --- mods/train/init.lua | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/mods/train/init.lua b/mods/train/init.lua index 2198d41..fe87750 100644 --- a/mods/train/init.lua +++ b/mods/train/init.lua @@ -224,17 +224,23 @@ local function coupling_logic(self) local coupler_goal = self.coupler1:get_luaentity().coupler_distance + local coupler_velocity = self.coupler1:get_velocity() + if self.axis_lock == "x" then local velocity_real = self.object:get_velocity() local distance = vector.distance(pos,pos2) local new_vel = vector.new(0,0,0) if distance > coupler_goal then - local velocity = (distance-coupler_goal)*2 + local velocity = (distance-coupler_goal)*5 local dir = vector.direction(vector.new(pos.x,0,0),vector.new(pos2.x,0,0)) self.dir = dir new_vel = vector.multiply(dir,velocity) else - new_vel = vector.multiply(velocity_real,-1) + if vector.equals(coupler_velocity,vector.new(0,0,0)) then + new_vel = vector.multiply(velocity_real,-1) + else + new_vel = vector.multiply(velocity_real,-0.05) + end end self.object:add_velocity(new_vel) elseif self.axis_lock == "z" then @@ -242,12 +248,16 @@ local function coupling_logic(self) local distance = vector.distance(pos,pos2) local new_vel = vector.new(0,0,0) if distance > coupler_goal then - local velocity = (distance-coupler_goal)*2 + local velocity = (distance-coupler_goal)*5 local dir = vector.direction(vector.new(0,0,pos.z),vector.new(0,0,pos2.z)) self.dir = dir new_vel = vector.multiply(dir,velocity) else - new_vel = vector.multiply(velocity_real,-1) + if vector.equals(coupler_velocity,vector.new(0,0,0)) then + new_vel = vector.multiply(velocity_real,-1) + else + new_vel = vector.multiply(velocity_real,-0.05) + end end self.object:add_velocity(new_vel) end -- 2.44.0