aboutsummaryrefslogtreecommitdiff
path: root/advtrains
diff options
context:
space:
mode:
authororwell96 <mono96.mml@gmail.com>2017-01-18 20:51:47 +0100
committerorwell96 <mono96.mml@gmail.com>2017-01-18 20:51:47 +0100
commit7ab41542166989a80920138b85add399927631e2 (patch)
tree54d31b5e069498eb5e8f586c3e1b3a1ba5f29164 /advtrains
parent341de7845a2ba1efce341eaa0f011093ac0e5f10 (diff)
downloadadvtrains-7ab41542166989a80920138b85add399927631e2.tar.gz
advtrains-7ab41542166989a80920138b85add399927631e2.tar.bz2
advtrains-7ab41542166989a80920138b85add399927631e2.zip
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.
Diffstat (limited to 'advtrains')
-rw-r--r--advtrains/advtrains/wagons.lua17
1 files 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