From 7ab41542166989a80920138b85add399927631e2 Mon Sep 17 00:00:00 2001 From: orwell96 Date: Wed, 18 Jan 2017 20:51:47 +0100 Subject: Add 'collision mercy' to get stuck trains out of walls. Also change the collision logic so that the collision mercy can't be activated accidentally. --- advtrains/advtrains/wagons.lua | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/advtrains/advtrains/wagons.lua b/advtrains/advtrains/wagons.lua index f164335..265a84c 100644 --- a/advtrains/advtrains/wagons.lua +++ b/advtrains/advtrains/wagons.lua @@ -377,9 +377,20 @@ function wagon:on_step(dtime) end end if collides then - gp.recently_collided_with_env=true - gp.velocity=-0.5*gp.velocity - gp.tarvelocity=0 + if self.collision_count and self.collision_count>10 then + --enable collision mercy to get trains stuck in walls out of walls + --actually do nothing except limiting the velocity to 1 + gp.velocity=math.min(gp.velocity, 1) + gp.tarvelocity=math.min(gp.tarvelocity, 1) + else + gp.recently_collided_with_env=true + gp.velocity=2*gp.velocity + gp.movedir=-gp.movedir + gp.tarvelocity=0 + self.collision_count=(self.collision_count or 0)+1 + end + else + self.collision_count=nil end end -- cgit v1.2.3