2022-07-28 15:44:31 +03:00

62 lines
1.5 KiB
Plaintext

--@include ./powertrain_component.txt
--@include /koptilnya/libs/constants.txt
--@include /koptilnya/libs/entity.txt
require('./powertrain_component.txt')
require('/koptilnya/libs/constants.txt')
require('/koptilnya/libs/entity.txt')
Wheel = class('Wheel', PowertrainComponent)
function Wheel:initialize(config, prefix)
PowertrainComponent.initialize(self)
self.prefix = prefix
self.wireInputs = {
[prefix .. 'Wheel'] = 'entity'
}
self.wireOutputs = {
[prefix .. 'RPM'] = 'number'
}
self.entity = NULL_ENTITY
hook.add('input', 'vehicle_wheel_update' .. prefix, function(key, val)
if key == prefix .. 'Wheel' then
self.entity = val
if not isValid(val) then
return
end
if config.CalculateInertia then
--self.entity:setInertia(calculateWheelInertia(val))
--print(calculateWheelInertia(val))
end
self.inertia = self.entity:getInertia().y
end
end)
end
function Wheel:updateWireOutputs()
wire.ports[self.prefix .. 'RPM'] = self:selfRPM()
end
function Wheel:queryAngularVelocity()
return self.angularVelocity
end
function Wheel:forwardStep(torque, inertia)
if not isValid(self.entity) then
return 0
end
--self.entity:setInertia(self.entity:getInertia():setY(inertia))
self.entity:applyTorque(torque * self.entity:getRight())
self.angularVelocity = self.entity:getAngleVelocity().y
return self.angularVelocity * self.inertia
end