InputEventMouseMotion doesn't work when a Control Node is present

Godot Version

v4.1.1.stable.official

Question

I wasn’t sure whether to put this in the Programming or UI category, but I figured it would work better in the UI category. I’m using a modified version of the built in 3D_Player_Movement script for a simple project I’m creating mainly for practice. Camera movement works completely fine, until the moment I add a control node to the node tree, at which point my camera can not move. I’ll admit that I haven’t done much with control nodes or 3D nodes, so it’s possible I’m missing something pretty big.

extends CharacterBody3D


const SPEED = 3.5
const sprintMultiplier = 2
const JUMP_VELOCITY = 3.5
var canJump = false

# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
@onready var neck := $NeckJoint
@onready var camera := $NeckJoint/PlayerCamera3D

func _ready() -> void:
	Input.mouse_mode = Input.MOUSE_MODE_CAPTURED

func _unhandled_input(event):
	if event is InputEventMouseMotion:
		neck.rotate_y(-event.relative.x * 0.01)

func _physics_process(delta):
	if Input.is_action_pressed("CharacterAction") and not canJump:
		camera.rotation_degrees = Vector3(0, 180, 0)
	else:
		camera.rotation_degrees = Vector3(0, 0, 0)
	# Add the gravity.
	if not is_on_floor():
		velocity.y -= gravity * delta

	# Handle Jump.
	if Input.is_action_just_pressed("CharacterAction") and is_on_floor() and canJump:
		velocity.y = JUMP_VELOCITY

	# Get the input direction and handle the movement/deceleration.
	# As good practice, you should replace UI actions with custom gameplay actions.
	var input_dir = Input.get_vector("MoveLeftward", "MoveRightward", "MoveForward", "MoveBackward")
	
	var direction = (neck.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
	if Input.is_action_pressed("Sprint"):
		direction = (neck.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized() * sprintMultiplier
	if direction:
		velocity.x = direction.x * SPEED
		velocity.z = direction.z * SPEED
	else:
		velocity.x = move_toward(velocity.x, 0, SPEED)
		velocity.z = move_toward(velocity.z, 0, SPEED)

	move_and_slide()

The scene looks like this. The only difference beforehand was no control or label node.
image

I’d really appreciate any help with this!

Well, you are using _unhandled_input() to control the mouse movement, but the thing about Control nodes is they DO handle input, so it is no longer unhandled. =P
Just change it to _input() and in will work as you expect.

1 Like