Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to simulate vehicle acceleration ?

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 )

3 comments

1

Upvoted, no idea about vehicles lol. Else i'd help

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?

0

Yes. I want to make it simple and clear, Speed is just the Vehicle Speed, I will apply it to the vehicle after.

1 answer

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.

1 comment

0

Oh ok, but how should I apply this to a vehicle ?

This discussion is preserved as it was. New answers, comments, and votes are closed.