Vehicle throttle problem

So the problem I’m having is that if you drive and run into the road, the car would spin and would accelerate fast after it stops.

I followed a tutorial from sleitnick.

local steer = 0
local throttle = 0

local function Update(delta)
	local steerGoal = -VehicleSeat.SteerFloat * maxSteerAngle.Value
	steer += (steerGoal - steer) * math.min(delta * turnSpeed.Value, 1)
	attachFL.Orientation = Vector3.new(attachFL.Orientation.X, steer, attachFL.Orientation.Z)
	attachFR.Orientation = Vector3.new(attachFL.Orientation.X, steer, attachFL.Orientation.Z)
	
	local throttleGoal = VehicleSeat.ThrottleFloat
	throttle += (throttleGoal - throttle) * math.min(delta * accelerationSpeed.Value, 1)
	local speed = maxSpeed.Value * throttle
	
	cylFL.AngularVelocity = speed
	cylFR.AngularVelocity = speed
	cylRL.AngularVelocity = speed
	cylRR.AngularVelocity = speed
end

local function Start()
	runServiceConnection = RunService.Heartbeat:Connect(Update)
end

Start()

I think it has something to do with Angular Velocity.

Looking at the throttle at the bottom, it increases fast after it stops spinning.

It’s your inf MaxAngularVelocity and MotorMaxTorque values.
I found in my cars if I set those too high the car wouldn’t sit still even while not in the seat and you could see the wheels start to spin & the vehicle would kind of jump around.

Set them to numbers that work for your car, not just Max.

2 Likes

Now my car is driving slow.

local function Update(delta)
	local steerGoal = -VehicleSeat.SteerFloat * maxSteerAngle.Value
	steer += (steerGoal - steer) * math.min(delta * VehicleSeat.TurnSpeed, 1)
	attachFL.Orientation = Vector3.new(attachFL.Orientation.X, steer, attachFL.Orientation.Z)
	attachFR.Orientation = Vector3.new(attachFL.Orientation.X, steer, attachFL.Orientation.Z)
	
	local throttleGoal = VehicleSeat.ThrottleFloat
	throttle += (throttleGoal - throttle) * math.min(delta * VehicleSeat.TurnSpeed, 1)
	local torque = VehicleSeat.Torque
	local speed = maxSpeed.Value * throttle
	cylFL.MotorMaxTorque = torque
	cylFR.MotorMaxTorque = torque
	cylRL.MotorMaxTorque = torque
	cylRR.MotorMaxTorque = torque
	
	cylFL.AngularVelocity = speed
	cylFR.AngularVelocity = speed
	cylRL.AngularVelocity = speed
	cylRR.AngularVelocity = speed
end

Also, when setting them to the max, it seems to be better. Why?

Video of the tutorial:

No, don’t set it in the script. Set it in the HingeConstraint Properties.
Just fine tune the values since the size of your car, mass of the car, Friction of the tires,
and size of the tires all have an effect.
Try a max torque of 20000 and see if that helps. If the car is too slow then you can make it larger.
Also the Max angular is the acceleration of the motor. If you fine tune it you may even be able to take the accelerationSpeed out of the script.
Screenshot 2023-06-03 174302

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