diff options
author | orwell96 <mono96.mml@gmail.com> | 2017-01-18 20:51:47 +0100 |
---|---|---|
committer | orwell96 <mono96.mml@gmail.com> | 2017-01-18 20:51:47 +0100 |
commit | 7ab41542166989a80920138b85add399927631e2 (patch) | |
tree | 54d31b5e069498eb5e8f586c3e1b3a1ba5f29164 | |
parent | 341de7845a2ba1efce341eaa0f011093ac0e5f10 (diff) | |
download | advtrains-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.
-rw-r--r-- | advtrains/advtrains/wagons.lua | 17 |
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
|