You can use the CFrame.new(Vector3 pos, Vector3 lookAt) constructor to make the HumanoidRootPart face a direction, which in this case is the (right) thumbstick position.
local UserInputService = game:GetService("UserInputService")
UserInputService.InputChanged:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Thumbstick2 then
local position = input.Position
-- If the stick goes 10% past the center, activate
if position.Magnitude > 0.1 then
Root.CFrame = CFrame.new(
Root.Position,
Root.Position + Vector3.new(position.X, 0, -position.Y)
)
end
end
end)
If you want to rotate it relative to the camera the solution is a bit more complex, but still similar:
local UserInputService = game:GetService("UserInputService")
local Workspace = game:GetService("Workspace")
local Camera = Workspace.CurrentCamera
local function Rotate(vector, angle)
return Vector2.new(
vector.X * math.cos(angle) + vector.Y * math.sin(angle),
-vector.X * math.sin(angle) + vector.Y * math.cos(angle)
)
end
UserInputService.InputChanged:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Thumbstick2 then
local position = input.Position
if position.Magnitude > 0.1 then
local look = Camera.CFrame.LookVector
local angle = math.atan2(look.Z, look.X) + math.pi / 2
position = Rotate(position.Unit, angle)
Root.CFrame = CFrame.new(
Root.Position,
Root.Position + Vector3.new(position.X, 0, -position.Y)
)
end
end
end)
Note: Both of these examples assume “Root” is the HumanoidRootPart