Analog stick movement pivoted around a central point?

I’m creating a top-down shooter, so I’ve decided to add controller support to the game. The question is, how would I accomplish the right stick pivoting around the center of the screen? I emulated this behaviour with a mouse, to better explain what i’m trying to do.
a3RYth05CR

1 Like

To get the right stick input, you’d have to connect to the UserInputService.InputBegan and single out the right thumbstick, as so:

UserInputService.InputChanged:Connect(function(input, processed)
	if input.UserInputType == Enum.UserInputType.Gamepad1 then
		if input.KeyCode == Enum.KeyCode.Thumbstick2 then
			print(input.Position.X, input.Position.Y)
                --Position.X returns from -1 to 1
                --Position.Y also returns from -1 to 1
		end
	end
end)

You could then substitute the input.Position values in for your mouse controls.

2 Likes

Thanks for the help. I took your code and placed it in a Frame that moves when you touch the stick. I was planning to make it so the player could shoot in the direction of the frame.

if input.KeyCode == Enum.KeyCode.Thumbstick2 then
	print(input.Position.X, input.Position.Y)
	local x = input.Position.X
	local y = input.Position.Y
	frame.Position = UDim2.new(x, 0, y, 0)
end

The problem is, 0 in UDim2 just defaults to the top left corner of the screen. How would I pivot the frame around the center of the screen instead?

UDim2.new(x*0.5 + 0.5, 0, -y*0.5 + 0.5, 0)

It’ll need a bit of tweaking to avoid going off the bottom right corner, but this should work otherwise.