Fixed suspension breaking when car was flipped
This commit is contained in:
parent
c8a817277a
commit
98fe60a765
@ -4,10 +4,10 @@
|
|||||||
|
|
||||||
local _restLength = 26.0
|
local _restLength = 26.0
|
||||||
local _springTravel = 20.0
|
local _springTravel = 20.0
|
||||||
local _springStiffness = 35000
|
local _springStiffness = 45000
|
||||||
local _compressionDamper = 140000 -- 45000
|
local _compressionDamper = 250000 -- 45000
|
||||||
local _reboundDamper = 35000 -- 196000
|
local _reboundDamper = 150000 -- 196000
|
||||||
local _maxForce = 500000
|
local _maxForce = 800000
|
||||||
|
|
||||||
local _minLength = 0
|
local _minLength = 0
|
||||||
local _maxLength = 0
|
local _maxLength = 0
|
||||||
@ -70,17 +70,18 @@ if SERVER then
|
|||||||
local strutToWheelDirection = (strut:getPos() - wheel:getPos()):setX(0):setY(0):getNormalized()
|
local strutToWheelDirection = (strut:getPos() - wheel:getPos()):setX(0):setY(0):getNormalized()
|
||||||
local springVelocity = (distance - lastLength)
|
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 spring = distance * _springStiffness
|
||||||
local dampener = springVelocity * usedDamper
|
local dampener = springVelocity * usedDamper
|
||||||
|
|
||||||
local force = math.clamp((spring + dampener) * game.getTickInterval(), -_maxForce, _maxForce)
|
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
|
lastLength = distance
|
||||||
|
|
||||||
base:applyForceOffset(-force * direction, wheel:getPos())
|
base:applyForceOffset(-force * baseDirection, wheel:getPos())
|
||||||
wheel:applyForceCenter(force * direction * strutToWheelDirection)
|
wheel:applyForceCenter(force * direction)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user