Roblox Tutorial Car Not Steering

Hello! I have just re-created the car shown in this tutorial:

Only to find that I can’t steer.

I have re-built the car multiple times, re-reading the entire tutorial, to no avail; The acceleration works fine, but the car can not steer.

When I press A or D, the HingeConstraint’s TargetAngle changes, as shown here:
image
But the wheels stay at the sides of the car.

How do I fix this?

File for my recreation of the tutorial car:
car file.rbxm (11.9 KB)

Note: The issue seems to be that the HingeConstraint’s TargetAngle changes, but the CurrentAngle remains the same.

Where is the code that is controlling this car? It would be helpful for you to post that.

He just sent a file… open it to see.

This is the code provided by Roblox:

local vehicleSeat = workspace.Base.VehicleSeat

local motorFR = workspace.WheelFR:FindFirstChildWhichIsA("CylindricalConstraint", true)
local motorFL = workspace.WheelFL:FindFirstChildWhichIsA("CylindricalConstraint", true)
local motorBR = workspace.WheelBR:FindFirstChildWhichIsA("CylindricalConstraint", true)
local motorBL = workspace.WheelBL:FindFirstChildWhichIsA("CylindricalConstraint", true)

local springFR = workspace.WheelFR:FindFirstChildWhichIsA("SpringConstraint", true)
local springFL = workspace.WheelFL:FindFirstChildWhichIsA("SpringConstraint", true)
local springBR = workspace.WheelBR:FindFirstChildWhichIsA("SpringConstraint", true)
local springBL = workspace.WheelBL:FindFirstChildWhichIsA("SpringConstraint", true)

local wheelHingeR = workspace.WheelFR:FindFirstChildWhichIsA("HingeConstraint", true)
local wheelHingeL = workspace.WheelFL:FindFirstChildWhichIsA("HingeConstraint", true)


-- TUNING VALUES
----------------------------------------
-- Factor of torque applied to get the wheels spinning
-- Larger number generally means faster acceleration
local TORQUE = 10000 

-- Factor of torque applied to change the wheel direction
-- Larger number generally means faster braking
local BRAKING_TORQUE = 8000

-- Max angle the wheels will reach when turning
-- Higher number means sharper turning, but too high means the wheels might hit the car base
local MAX_TURN_ANGLE = 45

-- Car max speed
local MAX_SPEED = 140
----------------------------------------


-- HELPER FUNCTIONS
----------------------------------------
-- Set the "MotorMaxTorque" property on all of the CylindricalConstraint motors
local function setMotorTorque(torque)
	motorFR.MotorMaxTorque = torque
	motorFL.MotorMaxTorque = torque
	motorBR.MotorMaxTorque = torque
	motorBL.MotorMaxTorque = torque
end

-- Set the "AngularVelocity" property on all of the CylindricalConstraint motors
local function setMotorVelocity(vel)
	motorFL.AngularVelocity = vel
	motorBL.AngularVelocity = vel
	-- Motors on the right side are facing the opposite direction, so negative velocity must be used
	motorFR.AngularVelocity = -vel
	motorBR.AngularVelocity = -vel
end

-- Calculate the average linear velocity of the car based on the rate at which all wheels are spinning
local function getAverageVelocity()
	local vFR = -motorFR.Attachment1.WorldAxis:Dot(motorFR.Attachment1.Parent.RotVelocity)
	local vRR = -motorBR.Attachment1.WorldAxis:Dot(motorBR.Attachment1.Parent.RotVelocity)
	local vFL = motorFL.Attachment1.WorldAxis:Dot(motorFL.Attachment1.Parent.RotVelocity)
	local vRL = motorBL.Attachment1.WorldAxis:Dot(motorBL.Attachment1.Parent.RotVelocity)
	return 0.25 * ( vFR + vFL + vRR + vRL )
end


-- DRIVE LOOP
----------------------------------------
while true do

	-- Input values taken from the VehicleSeat
	local steerFloat = vehicleSeat.SteerFloat  -- Forward and backward direction, between -1 and 1
	local throttle = vehicleSeat.ThrottleFloat  -- Left and right direction, between -1 and 1

	-- Convert "steerFloat" to an angle for the HingeConstraint servos
	local turnAngle = steerFloat * MAX_TURN_ANGLE
	wheelHingeR.TargetAngle = turnAngle
	wheelHingeL.TargetAngle = turnAngle

	-- Apply torque to the CylindricalConstraint motors depending on our throttle input and the current speed of the car
	local currentVel = getAverageVelocity()
	local targetVel = 0
	local motorTorque = 0

	-- Idling
	if math.abs(throttle) < 0.1 then
		motorTorque = 100

	-- Accelerating
	elseif math.abs(throttle * currentVel) > 0 then
		-- Reduce torque with speed (if torque was constant, there would be a jerk reaching the target velocity)
		-- This also produces a reduction in speed when turning
		local r = math.abs(currentVel) / MAX_SPEED
		-- Torque should be more sensitive to input at low throttle than high, so square the "throttle" value
		motorTorque = math.exp( - 3 * r * r ) * TORQUE * throttle * throttle
		targetVel = math.sign(throttle) * 10000  -- Arbitrary large number

	-- Braking
	else
		motorTorque = BRAKING_TORQUE * throttle * throttle
	end

	-- Use helper functions to apply torque and target velocity to all motors
	setMotorTorque(motorTorque)
	setMotorVelocity(targetVel)
	wait()
end```

I shouldn’t need to download a file to my computer to look over code.

The code is not the issue; It sets the TargetAngle properly. The issue is that the HingeConstraint isn’t moving the wheel.

You have a WeldConstraint between each WheelMount and the base. Those are keeping the wheels from turning. Delete those and you are off and running-- mostly. On each HingeConstraint, if you check LimitsEnabled (it will default to 45 and -45 degrees) it will keep your wheels from turning too far as you drive around.

1 Like

Thank you very much, I just found that out and went back here to post about it, only to see that you solved it too! Thank you very much, though!