Title says it all, I can’t find an simple example or tutorial that explains how to do this. I only know that there is RPM
, and Gear
variables involved.
1 Like
Perhaps you could take a look at how A-Chassis does it, in the “Drive” localscript.
I already looked at it, and I had hard time finding what I was looking for, so I decided to ask here first because perhaps someone would know how to instead of having to figure out how the drive script works. But if nobody will have an answer then I suppose I won’t have a choice.
After some extensive research on Google, I found Stack Exchange and Unity forum post.
But I am still not sure how I can get wheel RPM, and how to make automatic gear shifting. Right now I just have this:
-- Radians per second to revolutions per minute
local function rpsToRPM(rps: number)
return rps * 9.5493 * 4 -- extra * is for "weight" to simulate RPM
end
function Transmission:calcAverageDriveWheelsRPM()
self = self :: TransmissionMetatable
local leftWheelRPM = rpsToRPM(self.driveWheels[1].AssemblyAngularVelocity.Magnitude)
local rightWheelRPM = rpsToRPM(self.driveWheels[2].AssemblyAngularVelocity.Magnitude)
return (leftWheelRPM + rightWheelRPM) / 2
end
function Transmission:computeGear()
self = self :: TransmissionMetatable
if self.currentEngineRPM >= self.maxEngineRPM then
for i = 1, #self.gearRatio do
if self:calcAverageDriveWheelsRPM() * self.gearRatio[i] < self.maxEngineRPM then
self.currentGear = i
break
end
end
end
if self.currentEngineRPM <= self.minEngineRPM then
for i = 1, #self.gearRatio do
if self:calcAverageDriveWheelsRPM() * self.gearRatio[i] > self.minEngineRPM then
self.currentGear = i
break
end
end
end
end
2 Likes
RPM and torque are inversely proportional. You’d get your hinge and modify its RPM and max torque based on that.
2 Likes