Move vehicle relative to player camera

Basically, I want better mobile support for the vehicle system in my game, so I want the car to be driveable using thumbstick. If you’re facing forward and drag your thumbstick to the right it’ll go to the cameras right (exactly how default roblox character movement works). Right now I have a value called steer, if the value is positive it turns right, negative makes it turn left.

I have read quite a few devforum posts on how to do it but I am struggling with implementation. What I’ve tried is get what direction the car should be turned and by how much, depending on the values the thumbstick gives with ControlsModule:GetMoveVector(), add that to the orientation the car started with and then stop steering when it has reached that orientation. But for some reason the car just continues going in a circle.

Any help would be greatly appreciated.

Current Code:

local Player = game:GetService("Players").LocalPlayer
local PlayerModule = require(Player.PlayerScripts.PlayerModule)
local Controls = PlayerModule:GetControls()
local Camera = workspace.CurrentCamera
local InputVector = Controls:GetMoveVector()

if InputVector.Magnitude == 0 then
	return Vector3.new()
end

local InputForward = -InputVector.Z
local InputRight = InputVector.X
local CameraForwardVector = Camera.CFrame.LookVector
local CameraRightVector = Camera.CFrame.RightVector
local MoveVector = ((InputForward * CameraForwardVector) + (InputRight * CameraRightVector)).Unit
	
local Car = iFolder.Parent.Parent.Parent:FindFirstChild("ConnectedRC").Value
	
local CamX, CamY, CamZ = Camera.CFrame.Rotation:ToOrientation()
CamX, CamY, CamZ = math.deg(CamX), math.deg(CamY), math.deg(CamZ)
	
local CarX, CarY, CarZ = Car:GetPivot().Rotation:ToOrientation()
CarX, CarY, CarZ = math.deg(CarX), math.deg(CarY), math.deg(CarZ)
	
local RotateBy = MoveVector.X*90	
	
if MoveVector then
	iFolder:SetAttribute("Throttle", -MoveVector.Z)
	
	if CarX < CamY+RotateBy then
		iFolder:SetAttribute("Steer", -MoveVector.X)
	else
		iFolder:SetAttribute("Steer", MoveVector.X)
	end
end

this code doesn’t show how the cframe of the vehicle actually changes. i would like to see that.

For rotating wheels, servos where angle is adjusted.

For going forward there are hinges with actuatortype motor, their angularvelocity is increased if Throttle is > 0. (For PC it just sets throttle to 1 if you hold W)

are the servos reset when the input is finished?

If you mean reset as in put back to default values, then yes. Not completely destroyed and re-inserted though.

could i see the code around the actuator hinge?

RunService.Heartbeat:Connect(function()
	if Throttle > 0 then
		motor.MotorMaxTorque = 250
		motor.AngularVelocity = 70
	elseif Throttle < 0 then
		motor.MotorMaxTorque = 250
		motor.AngularVelocity = -70
	else
		motor.AngularVelocity = 0
	end
end)

i don’t think throttle reaches 0. the one of the first two comparisons will always run.
based on the code you provided, this works as intended for a constant input.
maybe you need some sort of inputEnded event to set throttle to 0 when not moving?

Nothing wrong with the throttle, you must have missunderstood. But I did end up figuring it out. Thanks for the help though.