]> git.lizzy.rs Git - Crafter.git/commitdiff
Tune coupling collision detection more
authoroilboi <47129783+oilboi@users.noreply.github.com>
Mon, 6 Jul 2020 01:16:15 +0000 (21:16 -0400)
committeroilboi <47129783+oilboi@users.noreply.github.com>
Mon, 6 Jul 2020 01:16:15 +0000 (21:16 -0400)
mods/train/init.lua

index fe8775069cf9174810e927ec4dfc81f150c70e96..aaa2605ad24c3950d72ce42c0f0df7273a6aec16 100644 (file)
@@ -239,7 +239,13 @@ local function coupling_logic(self)
                        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)
+                               local c_vel = vector.distance(vector.new(0,0,0),coupler_velocity)
+                               local a_vel = vector.distance(vector.new(0,0,0),velocity_real)
+                               local d_vel = a_vel-c_vel
+                               if d_vel < 0 then
+                                       d_vel = 0
+                               end
+                               new_vel = vector.multiply(self.dir,d_vel)
                        end
                end
                self.object:add_velocity(new_vel)
@@ -256,7 +262,13 @@ local function coupling_logic(self)
                        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)
+                               local c_vel = vector.distance(vector.new(0,0,0),coupler_velocity)
+                               local a_vel = vector.distance(vector.new(0,0,0),velocity_real)
+                               local d_vel = a_vel-c_vel
+                               if d_vel < 0 then
+                                       d_vel = 0
+                               end
+                               new_vel = vector.multiply(self.dir,d_vel)
                        end
                end
                self.object:add_velocity(new_vel)