diff options
author | orwell96 <mono96.mml@gmail.com> | 2016-06-09 17:35:06 +0200 |
---|---|---|
committer | orwell96 <mono96.mml@gmail.com> | 2016-06-09 17:35:06 +0200 |
commit | a879ce8d3c179b5c6b88c9db610d560228d1e5b4 (patch) | |
tree | 477a062c99baca9673b4127e89f49dab3e1d148c /trainlogic.lua | |
parent | e449704a92c8c1931fb687e58f095bea27db3ddc (diff) | |
download | advtrains-a879ce8d3c179b5c6b88c9db610d560228d1e5b4.tar.gz advtrains-a879ce8d3c179b5c6b88c9db610d560228d1e5b4.tar.bz2 advtrains-a879ce8d3c179b5c6b88c9db610d560228d1e5b4.zip |
Fix train collision and coupling on opposing trains, and try to implement animation (currently does not work)
Diffstat (limited to 'trainlogic.lua')
-rw-r--r-- | trainlogic.lua | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/trainlogic.lua b/trainlogic.lua index de56d4e..f7a9363 100644 --- a/trainlogic.lua +++ b/trainlogic.lua @@ -574,16 +574,18 @@ function advtrains.try_connect_trains_and_check_collision(id1, id2) for i=(advtrains.get_train_end_index(train2)+0.5),train2.index-0.5 do local testpos=advtrains.get_real_index_position(train2.path,i) if vector.distance(testpos, backpos1) < 0.5 then + local v2_sign = math.sign(i - ((train2.index-0.5) - ( (train2.index-0.5)-(advtrains.get_train_end_index(train2)+0.5) / 2 ))) --TODO physics train1.velocity=1 - train2.velocity=-1 + train2.velocity=v2_sign train1.recently_collided_with_env=true train2.recently_collided_with_env=true return end if vector.distance(testpos, frontpos1) < 0.5 then + local v2_sign = math.sign(i - ((train2.index-0.5) - ( (train2.index-0.5)-(advtrains.get_train_end_index(train2)+0.5) / 2 ))) train1.velocity=-1 - train2.velocity=1 + train2.velocity=v2_sign train1.recently_collided_with_env=true train2.recently_collided_with_env=true return @@ -680,7 +682,7 @@ function advtrains.invert_train(train_id) local old_path=advtrains.get_or_create_path(train_id, train) train.path={} - train.index= - advtrains.get_train_end_index(train1) + train.index= - advtrains.get_train_end_index(train) train.velocity=-train.velocity train.tarvelocity=-train.tarvelocity for k,v in pairs(old_path) do |