Hello! I have a problem trying to simulate vehicle acceleration, I tried doing for i loops
Seat.Changed:Connect(function() for currentspeed, 100 do wait(1) Speed = Speed + 1 end end)
or using repeat
loop
Seat.Changed:Connect(function(pro) local input = Seat.Throttle repeat wait(.5) Speed = Speed + 1 until seat.Throttle ~= input end)
Hope you can help! (And thanks for reading :D )
There's a lot of ways you can do this. Easiest way is to simulate a throttle and turn that into RPM. Then you can grab a gear ratio to simulate transmission and turn that into speed. Here's a little script I wrote.
local Throttle = 0 local RPM = 0 local MaxRPM = 5000 local Speed = 0 local GearRatio = 1/4 --4:1, for every rotation of the wheel, four rotations of the engine were accomplished. don't worry about that too much as we aren't simulating it. for i = 0,1,0.02 do --increase throttle, and calculate speed. Throttle = i RPM = MaxRPM*Throttle Speed = RPM*GearRatio print(Speed) end
You can simulate fully the real interactions that occur between the throttle (and throttle valve) and the engine, alongside an actual transmission and clutch, and properly turn this all into a rotation velocity, but that's a huge amount of physics (and calculus) and not necessary, I assume.