diff --git a/content/scripts/player.gd b/content/scripts/player.gd index 4cb6397..3cb68d4 100644 --- a/content/scripts/player.gd +++ b/content/scripts/player.gd @@ -61,7 +61,6 @@ enum MovementType { VERTICAL, LATERAL } @export var max_iteration_count := 4 var jump_pressed := false -var escape_pressed_prev := false var gravity := 9.8 var _velocity: Vector3 = Vector3() @@ -93,26 +92,27 @@ func unlock_mouse() -> void: # TODO should this have an action associated? # TODO should it be in unhandled? func _input(event: InputEvent) -> void: + # Rotate body/camera if event is InputEventMouseMotion and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED: var motion := event as InputEventMouseMotion body.rotate_y(-motion.relative.x * mouse_sensitivity) head.rotate_x(-motion.relative.y * mouse_sensitivity) head.rotation.x = clamp(head.rotation.x, -1.4, 1.4) + # Toggle mouse capture mode + if event is InputEventKey && event.is_pressed(): + var key_event := event as InputEventKey + if key_event.keycode == KEY_ESCAPE: + if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED: + unlock_mouse() + else: + lock_mouse() + # TODO should this be in unhandled input? # TODO this should return void and just set the appropriate fields (input_dir!!) # Input buffering? lol lmao func get_input() -> Vector2: - # Toggle mouse capture mode - var escape_pressed_curr := Input.is_key_pressed(KEY_ESCAPE) - if escape_pressed_curr && !escape_pressed_prev: - if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED: - unlock_mouse() - else: - lock_mouse() - escape_pressed_prev = escape_pressed_curr - # We don't want to be moving if the mouse isn't captured! if Input.get_mouse_mode() != Input.MOUSE_MODE_CAPTURED: return Vector2(0, 0)