Reworking vehicle controller
This commit is contained in:
49
koptilnya/engine_remastered/gearboxes/base.txt
Normal file
49
koptilnya/engine_remastered/gearboxes/base.txt
Normal file
@@ -0,0 +1,49 @@
|
||||
Gearbox = class('Gearbox')
|
||||
|
||||
function Gearbox:initialize(config, clutch, axles)
|
||||
self.ratios = config.Ratios
|
||||
self.reverse = config.Reverse
|
||||
|
||||
self.rpm = 0
|
||||
self.gear = 0
|
||||
self.torque = 0
|
||||
|
||||
self.axles = axles or {}
|
||||
self.clutch = clutch
|
||||
|
||||
self:recalcRatio()
|
||||
end
|
||||
|
||||
function Gearbox:setGear(gear)
|
||||
if gear >= -1 and gear <= #self.ratios then
|
||||
self.gear = gear
|
||||
self:recalcRatio()
|
||||
end
|
||||
end
|
||||
|
||||
function Gearbox:recalcRatio()
|
||||
if self.gear == -1 then
|
||||
self.ratio = -self.reverse
|
||||
elseif self.gear == 0 then
|
||||
self.ratio = 0
|
||||
else
|
||||
self.ratio = self.ratios[self.gear]
|
||||
end
|
||||
end
|
||||
|
||||
function Gearbox:update()
|
||||
if self.clutch ~= nil then
|
||||
self.torque = self.clutch.torque * self.ratio
|
||||
end
|
||||
|
||||
local axlesRPM = table.map(self.axles, function(diff)
|
||||
return diff.avgRPM
|
||||
end)
|
||||
|
||||
local maxAxlesRPM = math.max(unpack(axlesRPM))
|
||||
|
||||
self.rpm = maxAxlesRPM * self.ratio
|
||||
end
|
||||
|
||||
function Gearbox:shift()
|
||||
end
|
||||
Reference in New Issue
Block a user