Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to detect when the Thumbstick1 Has moved left/right? (XBOX)

Asked by
Nikkulaos 229 Moderation Voter
6 years ago

I am working on a paltformer game, and i have it done for PC so far, but i am troubled on the Xbox part.

I am very new to scripting with XBOX compatible controls, and i only know how to keybind with the controller so far.

I am trying to find out how to detect when the player moves the Thumbstick1 to the left/right, like how you can detect if someone presses A/D to move left/right.

I need it because on my came when they press A, they face left and when they press D they face right. I cant figure out how to do it for controllers.

If you can help please do. Thanks!

Keybind version:

local Player = game.Players.LocalPlayer

repeat wait() until Player.Character

local Character = Player.Character
local Torso = Character.UpperTorso
local Mouse = Player:GetMouse()

Character.Humanoid.AutoRotate = false

local bp = Instance.new("BodyPosition", Torso)
bp.MaxForce = Vector3.new(0, 0, math.huge)
bp.Position = Vector3.new(0, 0,Torso.Position.Z)

Mouse.KeyDown:connect(function(key)
if key == "a" then
Character.UpperTorso.CFrame = CFrame.new(Character.UpperTorso.Position, workspace.Left.Position)
elseif key == "d" then
Character.UpperTorso.CFrame = CFrame.new(Character.UpperTorso.Position, workspace.Right.Position)
end
end)


1 answer

Log in to vote
1
Answered by 6 years ago

It is impossible to use it with the thumbpad, but you could use the DPAD to move.

game:GetService("UserInputService").InputBegan:connect(function(input)
    if input.UserInputType == Enum.UserInputType.Gamepad1 then
        if input.KeyCode == Enum.KeyCode.DPadLeft then
            Character.UpperTorso.CFrame = CFrame.new(Character.UpperTorso.Position,workspace.Left.Position)
    elseif input.KeyCode == Enum.KeyCode.DPadRight then
            Character.UpperTorso.CFrame = CFrame.new(Character.UpperTorso.Position,workspace.Right.Position)
        end
    end
end)

I see what you're trying to do.

0
Oh Ok. Thanks for that Lol. Nikkulaos 229 — 6y
Ad

Answer this question