mouse input locks when lmb or rmb is pressed

Godot Version 4.2.2

Question

i am making a 3d multiplayer fps in godot 4.2.2 when ever we press rmb or lmb (only Lmb is used in code currently) we are unable to look around

extends CharacterBody3D

signal health_changed(health)

# gets outsiders 
@onready var Player = $"."
@onready var cam = $Camera3D
@onready var animPlayer = $AnimationPlayer
@onready var muzzle_flash = $Camera3D/pistol/muzzleFlash
@onready var raycast = $Camera3D/RayCast3D
@onready var deaths = $CanvasLayer/HUD/Deaths

# public variables
@export var health = 3
@export var SPEED = 8.7
@export var JUMP_VELOCITY = 6.8

# cans and cants
var canDoubleJump = false
var canSprint = true

# set World variables
var gravity = 20.0
var death = 0

func _enter_tree():
	set_multiplayer_authority(str(name).to_int())

# handle mice
func _ready():
	if not is_multiplayer_authority(): return
	
	Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
	cam.current = true

func _unhandled_input(event):
	if not is_multiplayer_authority(): return
	# alex the mice moover
	if event is InputEventMouseMotion:
		rotate_y(-event.relative.x * .005)	
		cam.rotate_x(-event.relative.y * .005)
		cam.rotation.x = clamp(cam.rotation.x, -PI/2, PI/2)

	# shootermc shoots alot
	if Input.is_action_just_pressed("shoot"):
		print("shot")
		play_shoot_effect.rpc()
		if raycast.is_colliding():
			var hit_player = raycast.get_collider()
			hit_player.recive_damage.rpc_id(hit_player.get_multiplayer_authority())

#mostly movement
func _physics_process(delta):
	if not is_multiplayer_authority(): return
	# Add the gravity.
	if not is_on_floor():
		velocity.y -= gravity * delta

	# Handle jump and double jump
	if Input.is_action_just_pressed("ui_accept") and canDoubleJump == true:
		velocity.y = JUMP_VELOCITY
		canDoubleJump = false
	else:
		pass
	if Input.is_action_just_pressed("ui_accept") and is_on_floor():
		velocity.y = JUMP_VELOCITY
		canDoubleJump = true

	# Get the input direction and handle the movement/deceleration.
	var input_dir = Input.get_vector("left", "right", "up", "down")
	var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
	if direction:
		velocity.x = direction.x * SPEED
		velocity.z = direction.z * SPEED
	else:
		velocity.x = move_toward(velocity.x, 0, SPEED)
		velocity.z = move_toward(velocity.z, 0, SPEED)
		
		# Sprinting
	if Input.is_action_pressed("boost") and canSprint == true:
		print(SPEED)
		SPEED = 13.2
	else:
		SPEED = 8.7
		
		# Crouching
	if Input.is_action_pressed("crouch"):
		Player.scale.y = .5
		cam.position.y = 1.119
		SPEED = 5.9
		canSprint = false
	else:
		Player.scale.y = 1
		cam.position.y = 1.619
		SPEED = 8.7
		canSprint = true
		
	# Pistol Anims
	if animPlayer.current_animation == "Shoot":
		pass
	elif input_dir != Vector2.ZERO and is_on_floor():
		animPlayer.play("Move")
	else: animPlayer.play("Idle")

	move_and_slide()
	
@rpc("call_local")
func play_shoot_effect():
	print("shoot")
	animPlayer.stop()
	animPlayer.play("Shoot")
	muzzle_flash.restart()
	muzzle_flash.emitting = true

@rpc("any_peer")
func recive_damage():
	health -= 1
	if health <= 0:
		health = 3
		position = Vector3.ZERO
		health_changed.emit(health)
	

func _on_animation_player_animation_finished(anim_name):
	if anim_name == "Shoot":
		animPlayer.play("Idle")

this is the script I use for the camera control

func _unhandled_input(event: InputEvent): 
	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)

neck is a node3d
camerea is camera3d
the neck is the the parent of the camera
and neck is a child the character/rigid body
hopefully this helps
@bcgamesdevs

1 Like