Fixed suspension breaking when car was flipped

This commit is contained in:
Ivan Grachyov 2022-07-28 00:18:35 +03:00
parent c8a817277a
commit 98fe60a765

View File

@ -4,10 +4,10 @@
local _restLength = 26.0
local _springTravel = 20.0
local _springStiffness = 35000
local _compressionDamper = 140000 -- 45000
local _reboundDamper = 35000 -- 196000
local _maxForce = 500000
local _springStiffness = 45000
local _compressionDamper = 250000 -- 45000
local _reboundDamper = 150000 -- 196000
local _maxForce = 800000
local _minLength = 0
local _maxLength = 0
@ -70,17 +70,18 @@ if SERVER then
local strutToWheelDirection = (strut:getPos() - wheel:getPos()):setX(0):setY(0):getNormalized()
local springVelocity = (distance - lastLength)
local usedDamper = springVelocity > 0 and _compressionDamper or _reboundDamper
local usedDamper = springVelocity > 0 and _reboundDamper or _compressionDamper
local spring = distance * _springStiffness
local dampener = springVelocity * usedDamper
local force = math.clamp((spring + dampener) * game.getTickInterval(), -_maxForce, _maxForce)
local direction = (strut:getPos() - wheel:getPos()):getNormalized() --base:getUp()
local direction = (strut:getPos() - wheel:getPos()):getNormalized()
local baseDirection = direction * Vector(0, 0, math.clamp(base:getUp().z, 0, 1))
lastLength = distance
base:applyForceOffset(-force * direction, wheel:getPos())
wheel:applyForceCenter(force * direction * strutToWheelDirection)
base:applyForceOffset(-force * baseDirection, wheel:getPos())
wheel:applyForceCenter(force * direction)
end
end