Skip to content

Commit

Permalink
Fix deadly environmental collisions destroying plane upon entry
Browse files Browse the repository at this point in the history
Last velocity was not cleared, thus it thinks the plane was involved in a hard
impact.
  • Loading branch information
jaihysc committed Dec 23, 2022
1 parent 05253d9 commit e1e670b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
---------------------------------------------------------------------------------------------------
Version: 1.5.2
Date: 2022-12-22
Bugfixes:
- Fix plane getting destroyed when you enter a new plane after crashing a plane with "Deadly environmental impacts"
---------------------------------------------------------------------------------------------------
Version: 1.5.1
Date: 2022-11-26
Features:
Expand Down
2 changes: 1 addition & 1 deletion info.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "AircraftRealism",
"version": "1.5.1",
"version": "1.5.2",
"title": "Aircraft Realism",
"author": "haih_ys",
"homepage": "https://forums.factorio.com/viewtopic.php?f=190&t=73964",
Expand Down
17 changes: 12 additions & 5 deletions logic/planeCollisions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ local function obstacleCollision(settings, surface, player, plane)
-- Destroy plane on large deceleration
if global.lastSpeed[player.index] then
local acceleration = plane.speed - global.lastSpeed[player.index]

-- Stopped (< 5 km/h) with deceleration over 40km/h
if math.abs(plane.speed) < 5 / 216 and math.abs(acceleration) > 40 / 216 then
plane.die()
return
-- Trigger on deceleration only, not acceleration
if (global.lastSpeed[player.index] > 0 and acceleration < 0) or (global.lastSpeed[player.index] < 0 and acceleration > 0) then
-- Stopped (< 5 km/h) with deceleration over 40km/h
if math.abs(plane.speed) < 5 / 216 and math.abs(acceleration) > 40 / 216 then
plane.die()
return
end
end
end
global.lastSpeed[player.index] = plane.speed
Expand All @@ -58,6 +60,11 @@ local function onTick(e)
-- Test for obstacle collision (water, cliff)
obstacleCollision(settings, player.surface, player, player.vehicle)
end
else
-- Clear last speed (Fixes bug with planes getting destroyed when you enter)
if global.lastSpeed and global.lastSpeed[player.index] then
global.lastSpeed[player.index] = nil
end
end
end
end
Expand Down

0 comments on commit e1e670b

Please sign in to comment.