im working on a car game and i just thought of something…
so my current system for the engines pitch is just based on its velocity (very simple)
But how could i get the RPM of the wheels then do a calculation to get the average, and then make that change the engines pitch? does anyone know how to do this?
You may be able to:
Wheel.Velocity.Magnitude-- Should return a number
Nevermind, try this code from another topic. It’s meant for sound but you may be able to use it for the speed of wheels.
local maxSpeed = 30
game:GetService("RunService").Heartbeat:Connect(function()
local velocity = MyCar.Body.Seat.AssemblyLinearVelocity.Magnitude
MyCar.EngineSound.PlaybackSpeed = (velocity / maxSpeed) + 0.6
end)
part.AssemblyAngularVelocity
for rotation
ok thanks, how would i get the average of each wheel tho?
like if 2 wheels are going 1 and 3, then the average would be 2
local wheelHolder = --a place to hold each wheel
local sum = 0
local count = 0
for _, wheel in ipairs(wheelHolder:GetChildren()) do
sum += wheel.AssemblyAngularVelocity
count += 1
end
local average = sum/count