Godot is not capturing mouse

Godot Version

v4.3.stable

Question

Im still new to coding, coming back after a few months since brackeys just uploaded his new 3d game video. I tried out his Proto-controller, but the mouse would not get captured. I cannot figure out why it is not working. Here is the code:

func _unhandled_input(event: InputEvent) -> void:
	# Mouse capturing
	if Input.is_mouse_button_pressed(1):
		print("Hello, world!")
		capture_mouse()

func capture_mouse():
	Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
	mouse_captured = true

The "print(“Hello, world!)” is not being displayed in the console either, so it must be something with the if input.is_mouse_button_pressed(1):

When using _input or _unhandled_input you need to use the event parameter, best with actions.

func _unhandled_input(event: InputEvent) -> void:
	# Mouse capturing
	if event is InputEventMouseButton:
		if event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
			print("Hello, world!")
			capture_mouse()
	# if you have an action declared in your input map
	if event.is_action_pressed("Click"):
		capture_mouse()

that still had the same result :frowning:

turns out I applied the wrong script, so nothing was updating lol. Fixed now :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.