Code misfunctional

i copied a piece of code from another project of mine but it just doesn’t work so i am here to ask for help with gratitude.

func _unhandled_input(event):
	if event is InputEventMouseMotion:
		head.rotate_y(-event.relative.x * SENSITIVITY)
		camera.rotate_x(-event.relative.y * SENSITIVITY)
		camera.rotation.x = clamp(camera.rotation.x, deg_to_rad(-80), deg_to_rad(80))

feel free to give me any recommendations. thank you.

Are there any error messages?

1 Like

When you say it doesn’t work, do you mean that the game errors, or that the game doesn’t error but nothing happens, or that something happens but it’s not the expected result?

1 Like

there’s no errors at all and no result on the client

Print something to see if the event handler even gets called.

1 Like
func _input(event):
	if event is InputEventMouseMotion:
		head.rotate_y(-event.relative.x * SENS)
		camera.rotate_x(-event.relative.y * SENS)
		camera.rotation.x = clamp(camera.rotation.x, deg_to_rad(-60), deg_to_rad(90))

it seems that the _unhandled_inputis deprecated in the latest version because this works

It’s not deprecated. Something else in your scene likely consumes the event.

1 Like

Since you asked for feedback on your code, I recommend:

# Don't use magic numbers. This avoids that.
const MINIMUM_ROTATION = -60.0
const MAXIMUM_ROTATION = 90.0

# Export your mouse sensitivity values so you can play with
# them, and later allow your player to set them. Also, best
# practice is to use full, descriptive names for variables.
# Typically people want a slower speed vertically, and a
# faster one horizontally.
@export var mouse_sensitivity_x: float = 0.075 #or whatever you set it at
@export var mouse_sensitivity_y: float = 0.075 #or whatever you set it at

# Adding explicit types to your arguments and return values
# will save you headaches down the road.
func _input(event: InputEvent) -> void:
	if event is InputEventMouseMotion:
		head.rotate_y(-event.relative.x * mouse_sensitivity_x)
		camera.rotate_x(-event.relative.y * mouse_sensitivity_y)
		camera.rotation.x = clamp(camera.rotation.x, deg_to_rad(MINIMUM_ROTATION), deg_to_rad(MAXIMUM_ROTATION))

Also, on what @normalized said: The problem was not with your code or the new version. Something in your game is eating the inputs before they get to _unhandled_input(). Keep that in mind for the next time you have an input that isn’t working the way you think it should.