Im entirely new to learning godot and written programming in general, im attempting to make a 3d fps game and was watching a tutorial on how to make movement and get camera movement, there is an issue in my code though specifically on line 16 (the get_mouse_mode line), any help?
func _unhandled_input(event: InputEvent) -> void:
if event is InputEventMouseButton:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
elif event.is_action_pressed("ui_cancel"):
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
if event is InputEventMouseMotion:
neck.rotate_y(-event.relative.x * 0.01)
camera.rotate_x(-event.relative.y * 0.01)
camera.rotation.x = clamp(camera.rotation.x, deg_to_rad(-30), deg_to_rad(60))
Is the error about indentation? Something like “Expected indented block”?
In GDScript indenting is very important, it’s how functions and if statements determine what lines of code are part of their effects. Since everything after the first line is indented it’s all part of the func _unhandled_input. Then we only set the mouse mode when a mouse button is pressed.
if event is InputEventMouseButton:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
Then this is where your error is, notice it will only check if mouse mode when ui_cancel is pressed. There is code after this mouse mode if statement, but it’s not indented so it wouldn’t run anything even if it was true, this lack of code also produces a syntax error.
elif event.is_action_pressed("ui_cancel"):
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
I think you mean to have this indentation:
func _unhandled_input(event: InputEvent) -> void:
if event is InputEventMouseButton:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
elif event.is_action_pressed("ui_cancel"):
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
if event is InputEventMouseMotion:
neck.rotate_y(-event.relative.x * 0.01)
camera.rotate_x(-event.relative.y * 0.01)
camera.rotation.x = clamp(camera.rotation.x, deg_to_rad(-30), deg_to_rad(60))