Hi everyone !

I am thinking about a little shooter game with a PS3 controller. I've read the example project call joystick to see how it work but I have several question ( I put the code below) : - What is the DEADZONE ? - How can I make a variable to change the sensibility of the joystick ? - is joy_connectetion_changed a function already define somewhere in Godot and called automatically when a device is detected ?

the script of the example project : ` extends Node2D

# Member variables
var joy_num
var cur_joy
var axis_value

const DEADZONE = 0.2

func _fixed_process(delta):
	# Get the joystick device number from the spinbox
	joy_num = get_node("joy_num").get_value()

# Display the name of the joystick if we haven't already
if joy_num != cur_joy:
	cur_joy = joy_num
	get_node("joy_name").set_text(Input.get_joy_name(joy_num))

# Loop through the axes and show their current values
for axis in range(JOY_ANALOG_0_X, JOY_AXIS_MAX):
	axis_value = Input.get_joy_axis(joy_num, axis)
	get_node("axis_prog" + str(axis)).set_value(100*axis_value)
	get_node("axis_val" + str(axis)).set_text(str(axis_value))
	# Show joystick direction indicators
	if (axis <= JOY_ANALOG_1_Y):
		if (abs(axis_value) < DEADZONE):
			get_node("diagram/axes/" + str(axis) + "+").hide()
			get_node("diagram/axes/" + str(axis) + "-").hide()
		elif (axis_value > 0):
			get_node("diagram/axes/" + str(axis) + "+").show()
		else:
			get_node("diagram/axes/" + str(axis) + "-").show()

# Loop through the buttons and highlight the ones that are pressed
for btn in range(JOY_BUTTON_0, JOY_BUTTON_MAX):
	if (Input.is_joy_button_pressed(joy_num, btn)):
		get_node("btn" + str(btn)).add_color_override("font_color", Color(1, 1, 1, 1))
		get_node("diagram/buttons/" + str(btn)).show()
	else:
		get_node("btn" + str(btn)).add_color_override("font_color", Color(0.2, 0.1, 0.3, 1))
		get_node("diagram/buttons/" + str(btn)).hide()

	func _ready():
		set_fixed_process(true)
		Input.connect("joy_connection_changed", self, "_on_joy_connection_changed")
	
	#Called whenever a joystick has been connected or disconnected.
	func _on_joy_connection_changed(device_id, connected):
		if device_id == cur_joy:
			if connected:
				get_node("joy_name").set_text(Input.get_joy_name(device_id))
			else:
				get_node("joy_name").set_text("")
	
	func _on_start_vibration_pressed():
		var weak = get_node("Vibration_weak_value").get_value()
		var strong = get_node("Vibration_strong_value").get_value()
		var duration = get_node("Vibration_duration_value").get_value()
	
		Input.start_joy_vibration(cur_joy, weak, strong, duration)
	
	func _on_stop_vibration_pressed():
		Input.stop_joy_vibration(cur_joy)`
24 days later

Joysticks which are at the center doesn't always send 0,0 as values. Therefore you use a deadzone. Otherwise the player might move around even if you don't touch the joystick. When you touch the joystick and you think you're at the center, you might not. The deadzone helps here too, to be not too sensitive.

Did you make any progress? I'm interested too.

10 months later

@LeFritz said: Joysticks which are at the center doesn't always send 0,0 as values. Therefore you use a deadzone. Otherwise the player might move around even if you don't touch the joystick. When you touch the joystick and you think you're at the center, you might not. The deadzone helps here too, to be not too sensitive.

Did you make any progress? I'm interested too.

Sorry, I stop to work on it and then I forget to come read answer here :sweat:

@Calinou said: Note that Godot 3.1 will ship with a new axis handling system, supporting a per-action dead zone value.

This is, by far, my favorite feature of 3.1.

I would definitely recommend waiting until 3.1 comes out (shouldn't be more than a few weeks now), and in the mean time you can check out the alpha and see just how well the axis handling system works. I've had no issues with it so far, and it works beautifully.

If anyone is curious to know what a dead zone is, I would highly suggest reading through this article from third-helix. It has what I would say is the best explanation of dead zones that I have seen, and it even has some helpful pictures and code samples showing how to make different types of dead zones.


I'm looking forward to trying Godot 3.1 and it's now axis system. I haven't had time to try the alpha yet, but looking at the article it looks super helpful! It certainly should make using cross platform/device joysticks much easier. Right now in Godot 3.0, supporting more than one joystick type (like a Xbox controller and a Playstation controller) requires some messy code.

4 years later