I have a custom camera script in my game that makes the camera input smooth but this only works for PC and I am trying to get it to work for an XBOX controller but I am completely unfamiliar with XBOX controller inputs.
Here is my code that detects the mouse movement:
input.InputChanged:connect(function(inputObject, gp)
if gp == true then
return
end
if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
local delta = Vector2.new(inputObject.Delta.x/Sensitivity,inputObject.Delta.y/Sensitivity) * Smoothness
local X = TargetAngleX - delta.y
TargetAngleX = (X >= 80 and 80) or (X <= -80 and -80) or X
TargetAngleY = (TargetAngleY - delta.x) %360
end
end)
I’d like to get this to work with the Right stick on an xbox controller if anyone has any insight that would be great!
Thanks
(I’d also like to convert it to work with mobile touch if anyone knows how to do that aswell)
InputObject.Delta has a code sample about how to handle different types of inputs. When it comes to gamepad input, you need to check if the UserInputType is a Gamepad (1-8). For thumbstick movement, the KeyCode will be a Thumbstick (1 for left, 2 for right). Your current code is probably compatible with gamepads already since you use the Delta as well rather than any mouse-specific properties.
Extra conditionals:
elseif inputObject.UserInputType == Enum.UserInputType.Gamepad1 and inputObject.KeyCode == Enum.KeyCode.Thumbstick2 then
Not sure how to do it for mobile though, sorry. Mobile development for me’s kinda weird.
Yes this works perfectly for mobile I just tried it here:
if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
local delta = Vector2.new(inputObject.Delta.x/Sensitivity,inputObject.Delta.y/Sensitivity) * Smoothness
local X = TargetAngleX - delta.y
TargetAngleX = (X >= 80 and 80) or (X <= -80 and -80) or X
TargetAngleY = (TargetAngleY - delta.x) %360
elseif inputObject.UserInputType == Enum.UserInputType.Gamepad1 then
local delta = Vector2.new(inputObject.Delta.X / Sensitivity, inputObject.Delta.Y / Sensitivity) * Smoothness
delta = delta * 1000
local X = TargetAngleX - delta.Y
TargetAngleX = (X >= 80 and 80) or (X <= -80 and -80) or X
TargetAngleY = (TargetAngleY - delta.x) %360
elseif inputObject.UserInputType == Enum.UserInputType.Touch then
local delta = Vector2.new(inputObject.Delta.x/Sensitivity,inputObject.Delta.y/Sensitivity) * Smoothness
delta = delta * 5
local X = TargetAngleX - delta.y
TargetAngleX = (X >= 80 and 80) or (X <= -80 and -80) or X
TargetAngleY = (TargetAngleY - delta.x) %360
end