Found a solution.
I found out the easiest way was to handle movement in a script, using Humanoid:Move
. When I found that out, I also got to work.
I found this topic after a long search which really helped, and put the IntControls function into my script, which handled the controls.
I modified the IntControls function to make it relative to the camera (which took me ages) and also removed Keyboard support because I wasn’t going to use it.
IntControls function
local function IntControls(character, gamepad, camera)
local Humanoid = character:WaitForChild("Humanoid")
local Up,Down,Left,Right = 0,0,0,0
local GamepadX,GamepadY = 0,0
local Jump = false
UIS.InputBegan:Connect(function(Key)
if UIS:GetFocusedTextBox() then return end
if Key.KeyCode == Enum.KeyCode.ButtonA and Key.UserInputType == gamepad then
Jump = true
end
end)
UIS.InputEnded:Connect(function(Key)
if UIS:GetFocusedTextBox() then return end
if Key.KeyCode == Enum.KeyCode.ButtonA and Key.UserInputType == gamepad then
Jump = false
end
end)
UIS.InputChanged:Connect(function(Key)
if Key.UserInputType == gamepad and Key.KeyCode == Enum.KeyCode.Thumbstick1 then
local X,Y = Key.Position.X,Key.Position.Y
if X < 0.1 and X > -0.1 then GamepadX = 0 else GamepadX = X end
if Y < 0.1 and Y > -0.1 then GamepadY = 0 else GamepadY = -Y end
end
end)
RenderStepped:Connect(function()
Humanoid:Move(camera.CFrame:VectorToWorldSpace(Vector3.new(Up + Down + GamepadX,0,Left + Right + GamepadY)), false)
if Jump == true then
Humanoid.Jump = true
end
end)
end