Gdscript help easiest way!

Godot Version

4.4.1

Question

Can someone explain this in the simplest way possible :

func _unhandled_input(event):
	if event is InputEventMouseMotion:
		rotation.y -= event.screen_relative.x * 0.001
		%Camera3D.rotation_degrees.x -= event.screen_relative.y * 0.1
		%Camera3D.rotation_degrees.x = clamp(
			%Camera3D.rotation_degrees.x, -60, 60
		)

On mouse move, it rotates the node around y axis depending on how much mouse moved horizontally. It also rotates the child camera node around the x axis depending on how much mouse moved vertically. The absolute x rotation of the camera node is then clamped to a range between -60 and 60 degrees.

1 Like