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