# Working on a car, confused on how this limits speed

I’m trying to make a car but I’m confused because I don’t know how the MaxSpeed Variable in the code below works. I don’t know why it needs to be divided by the radius of the wheel and the logic behind that.

Car script in car model
``````local car = script.Parent

local backLeft = car.BackLeft
local backRight = car.BackRight
local frontRight = car.FrontRight
local frontLeft = car.FrontLeft

local seat = car.VehicleSeat

local steerAngle = 30
local maxSpeed = seat.MaxSpeed / (frontLeft.Wheel.Size.Y/2)

seat:GetPropertyChangedSignal("SteerFloat"):Connect(function()
frontLeft.PartB.SteeringConstraint.TargetAngle = steerAngle * seat.SteerFloat
frontRight.PartB.SteeringConstraint.TargetAngle = steerAngle * seat.SteerFloat
end)

seat:GetPropertyChangedSignal("ThrottleFloat"):Connect(function()
frontLeft.Wheel.MotorConstraint.AngularVelocity = maxSpeed * seat.ThrottleFloat
frontRight.Wheel.MotorConstraint.AngularVelocity = maxSpeed * -seat.ThrottleFloat

backLeft.Wheel.MotorConstraint.AngularVelocity = maxSpeed * seat.ThrottleFloat
backRight.Wheel.MotorConstraint.AngularVelocity = maxSpeed * -seat.ThrottleFloat
end)
``````

The script probably adjusts the car’s max speed based on the size (radius) of the front left wheel. This is likely done to make sure that the car’s speed remains equal regardless of the size of the wheels.

So, think about the car’s max speed if it was still; no matter it’s wheel’s size. If the wheel was changed for smaller or bigger ones, the car’s speed will probably be too fast or unorganized.

Does this have something to do with physics as you said it’s adjusting the current max speed with the wheel?

Indeed;

v = r ⋅ ω

linear velocity, radius, omega.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.