Skip to content

Commit

Permalink
Allow cars to customize engine brake torque
Browse files Browse the repository at this point in the history
  • Loading branch information
StyledStrike committed Jan 6, 2025
1 parent 2a066b3 commit 7b474ee
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lua/entities/base_glide_car/sv_engine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ function ENT:EngineInit()

self.flywheelFriction = -7000
self.flywheelTorque = 20000
self.engineBrakeTorque = 500

-- Fake engine variables
self.reducedThrottle = false
Expand Down Expand Up @@ -133,11 +134,11 @@ end

local Remap = math.Remap

function ENT:GetTransmissionTorque( gear )
local torque = Remap( self:GetFlywheelRPM(), self:GetMinRPM(), self:GetMaxRPM(), self:GetMinRPMTorque(), self:GetMaxRPMTorque() )
function ENT:GetTransmissionTorque( gear, minTorque, maxTorque )
local torque = Remap( self:GetFlywheelRPM(), self:GetMinRPM(), self:GetMaxRPM(), minTorque, maxTorque )

-- Validation
torque = Clamp( torque, self:GetMinRPMTorque(), self:GetMaxRPMTorque() )
torque = Clamp( torque, minTorque, maxTorque )

-- Clutch
torque = torque * ( 1 - self.clutch )
Expand Down Expand Up @@ -360,15 +361,17 @@ function ENT:EngineThink( dt )
end

throttle = self:GetEngineThrottle()
gearTorque = self:GetTransmissionTorque( gear )
gearTorque = self:GetTransmissionTorque( gear, self:GetMinRPMTorque(), self:GetMaxRPMTorque() )
availableTorque = gearTorque * throttle

-- Simulate engine braking
if transmissionRPM < 0 then
-- The vehicle is moving against the current gear, do some hard engine braking.
availableTorque = availableTorque + gearTorque * 2
else
availableTorque = availableTorque - gearTorque * ( 1 - throttle ) * 0.5
-- The vehicle is coasting, apply a custom engine brake torque.
local engineBrakeTorque = self:GetTransmissionTorque( gear, self.engineBrakeTorque, self.engineBrakeTorque )
availableTorque = availableTorque - engineBrakeTorque * ( 1 - throttle ) * 0.5
end

-- Limit the engine RPM, check if it's redlining
Expand Down
2 changes: 2 additions & 0 deletions lua/entities/gtav_insurgent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ if SERVER then
end

function ENT:CreateFeatures()
self.engineBrakeTorque = 1300

self:SetBrakePower( 3800 )
self:SetDifferentialRatio( 3.3 )
self:SetPowerDistribution( -0.4 )
Expand Down
2 changes: 2 additions & 0 deletions lua/entities/gtav_speedo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ if SERVER then
}

function ENT:CreateFeatures()
self.engineBrakeTorque = 600

self:SetSpringStrength( 700 )
self:SetSteerConeMaxSpeed( 1000 )
self:SetForwardTractionBias( -0.15 )
Expand Down

0 comments on commit 7b474ee

Please sign in to comment.