Reworking vehicle controller

This commit is contained in:
Ivan Grachyov
2021-11-12 20:47:12 +05:00
parent 1650ac9a6d
commit b5fb04cce8
7 changed files with 169 additions and 30 deletions

View 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