Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
3

How to simulate vehicle acceleration ?

Asked by 4 years ago
Edited 4 years ago

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 )

1
Upvoted, no idea about vehicles lol. Else i'd help I_Nev 200 — 4y
1
Can you provide a bit more context. What are you doing with the variable 'Speed' other than changing it's value? Are you applying it to the vehicle somehow? Kibloxen 1 — 4y
0
Yes. I want to make it simple and clear, Speed is just the Vehicle Speed, I will apply it to the vehicle after. Nguyenlegiahung 1091 — 4y

1 answer

Log in to vote
1
Answered by
marfit 104
4 years ago
Edited 4 years ago

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.

0
Oh ok, but how should I apply this to a vehicle ? Nguyenlegiahung 1091 — 4y
Ad

Answer this question