Added direction option to wheel config

This commit is contained in:
Nikita Kruglickiy 2022-07-28 16:06:48 +03:00
parent d432b3220a
commit ca83cc2515
2 changed files with 6 additions and 5 deletions

View File

@ -24,7 +24,7 @@ function Differential:initialize(config, order)
CalculateInertia = true
}
self.outputA = Wheel:new(wheelConfig, prefix .. 'Left')
self.outputB = Wheel:new(wheelConfig, prefix .. 'Right')
self.outputB = Wheel:new(table.merge(wheelConfig, { Direction = -1 }), prefix .. 'Right')
table.merge(self.wireInputs, self.outputA.wireInputs)
table.merge(self.wireInputs, self.outputB.wireInputs)

View File

@ -12,12 +12,13 @@ function Wheel:initialize(config, prefix)
PowertrainComponent.initialize(self)
self.prefix = prefix
self.direction = config.Direction or 1
self.wireInputs = {
[prefix .. 'Wheel'] = 'entity'
}
self.wireOutputs = {
[prefix .. 'RPM'] = 'number'
[prefix .. 'WheelRPM'] = 'number'
}
self.entity = NULL_ENTITY
@ -41,7 +42,7 @@ function Wheel:initialize(config, prefix)
end
function Wheel:updateWireOutputs()
wire.ports[self.prefix .. 'RPM'] = self:selfRPM()
wire.ports[self.prefix .. 'WheelRPM'] = self:getRPM()
end
function Wheel:queryAngularVelocity()
@ -54,8 +55,8 @@ function Wheel:forwardStep(torque, inertia)
end
--self.entity:setInertia(self.entity:getInertia():setY(inertia))
self.entity:applyTorque(torque * self.entity:getRight())
self.angularVelocity = self.entity:getAngleVelocity().y
self.entity:applyTorque(torque * self.direction * self.entity:getRight())
self.angularVelocity = self.entity:getAngleVelocity().y * self.direction * TICK_INTERVAL
return self.angularVelocity * self.inertia
end