Hi all,
Recently I made a physics-based train system for my game, but the acceleration and deceleration is rather unrealistic. In my system, the speed is exactly proportional to the throttle. However, I want the speed to gradually rise and meet the throttle when it is changed, instead of changing to exactly the throttle immediately. Is there any way to do this with physics? Any help is appreciated!
(Here’s my current script for train movement using the default Roblox VehicleSeat as a throttle controller.)
if seat.Occupant == nil then
for i,wheel in pairs(wheels:GetChildren()) do
if wheel:IsA("HingeConstraint") then
wheel.AngularVelocity = 0
end
end
soundUpdate(seat)
end
if seat.Throttle == 1 then --stop
repeat
for i,wheel in pairs(wheels:GetChildren()) do
if wheel:IsA("HingeConstraint") and wheel.AngularVelocity < 300 then
wheel.AngularVelocity += 0.05
end
end
task.wait()
soundUpdate(seat)
event:FireClient(game:GetService("Players"):FindFirstChild(seat.Occupant.Parent.Name), seat.Velocity.Magnitude)
until seat.Throttle ~= 1
soundUpdate(seat)
elseif seat.Throttle == -1 then --stop
repeat
for i,wheel in pairs(wheels:GetChildren()) do
if wheel:IsA("HingeConstraint") and wheel.AngularVelocity > -300 then
wheel.AngularVelocity -= 0.06
end
end
task.wait()
soundUpdate(seat)
event:FireClient(game:GetService("Players"):FindFirstChild(seat.Occupant.Parent.Name), seat.Velocity.Magnitude)
until seat.Throttle ~= -1 or seat.Velocity.Magnitude < 2
soundUpdate(seat)
end