I have a player that aims and shoots at things. I am trying to add gamepad support, but am having trouble as the tutorial I read is godot 4.0 which I don't have. Can someone help me?

#as part of process, gamepad is whether we are using a gamepad, and it works, "leftStick" contains all axes for Device 0, Left Stick
if !gamepad:
		look_at(get_global_mouse_position())
		rotation_degrees += 90
	else:
		var joystick_vector = Vector2(Input.get_joy_axis(0, 0), Input.get_joy_axis(0, 1)).normalized()
		if joystick_vector.abs() > Vector2(0.1, 0.1)):
			rotation = joystick_vector.angle()+PI/2

It makes a deadzone aimed up and down, I think because then the X value is too low.

@Megalomaniak said: Heres the link for the page as it applies to latest stable build of the engine, perhaps that helps: https://docs.godotengine.org/en/stable/tutorials/inputs/controllers_gamepads_joysticks.html

And note that you can select the version the docs apply to at the bottom left of the docs.

That documentation was incorrectly backported, see https://github.com/godotengine/godot-docs/issues/5012. Edit: The feature will be available in Godot 3.4 and later: https://github.com/godotengine/godot/pull/50788

Okay, because those links to the docs lead to the thing I looked at.

15 days later

It's a little old at this point (and will be removed in Godot 4.0+), but the Godot 3D FPS tutorial I wrote has some code for using a deadzone on a joystick that may be helpful.

Okay so the main idea is this:

var joypad = Vector2(Input.get_joy_axis(0, 0), -Input.get_joy_axis(0, 1)) # Or there is different stuff for X11 and OSX in what @TwistedTwigleg said.
var joypad_vec = Vector2() #the final output, including deadzone.
var JOYPAD_DEADZONE = 0.3 # Something like this
if joypad_vec.length() < JOYPAD_DEADZONE:
#Not past the deadzone, so no input
        joypad_vec = Vector2(0, 0)
    else:
# Past the deadzone, do whatever weird math this is to get the vector.
        joypad_vec = joypad_vec.normalized() * ((joypad_vec.length() - JOYPAD_DEADZONE) / (1 - JOYPAD_DEADZONE))

Not tested(yet) but should work.

@Perodactyl said: Okay so the main idea is this: -snip- Not tested(yet) but should work.

You do not need to hardcode the deadzones or get the axes manually. Use the input action system which does this for you, and allows easy remapping if needed. See the Controllers, gamepads and joysticks documentation. (Note that get_vector() and get_axis() are only available in 3.4beta2 and later.)

21 days later

The docs say nothing about getting deadzones without the ones that are in the beta.

a year later