I’m working on a pause screen for my game, and have managed to get it to toggle on and off with the escape key. However, the tutorial I followed did not include instructions on how to use the mouse, and since the pause screen is a canvas overlay, I have concluded that the player’s camera code is causing the mouse to be stuck in the middle of the screen.
The code for said camera is in a script attached to my player, but I don’t know how I could stop the mouse from being fixed to the center while the pause overlay is there. Maybe I’m just dumb, but if anyone has any pointers, I’d greatly appreciate it.
extends Node3D
var sensitivity = 0.2
@onready var torch: SpotLight3D = $Camera3D/Torch
func _ready() -> void:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _input(event: InputEvent) -> void:
# Get mouse motion and handle the camera's rotation.
if event is InputEventMouseMotion:
get_parent().rotate_y(deg_to_rad(-event.relative.x * sensitivity))
rotate_x(deg_to_rad(-event.relative.y * sensitivity))
rotation.x = clamp(rotation.x, deg_to_rad(-90), deg_to_rad(90))
# Toggle the torch on and off.
if event.is_action_pressed("torch"):
torch.visible = not torch.visible
this given code is problem when we set the mouse mode captured it locked down to the center. you simply change the mouse_mode from captured to anything else like confined. This solve your problem.
use this whenever you want to move your mouse to move freely Input.set_mouse_mode(Input.MOUSE_MODE_CONFINED)
OK, I added those mouse mode lines and that fixed the problem, but now I can actually interact with the menu, I’ve noticed two more bugs:
Pressing the escape key (which I set as the pause input) resets the mouse to the middle of the screen instead of unpausing the game, which it did before implementing your fix.
Upon pressing the button to return to the title screen scene, I am unable to click any of the buttons in it.
Here is my menu code if it makes things any easier.