FPS camera movement suddenly stopped working

Godot Version

4.4.1.stable.steam

Question

My FPS camera script (that I got from LegionGames) was working before, but now I can’t move the camera, I don’t know if any of the other changes that I did on the game affected the script, and I didn’t even really touch the script itself at all

Here’s the code of the player script:

extends CharacterBody3D

@export var WALK_SPEED = 6.0
@export var speed = WALK_SPEED
@export var SPRINT_SPEED = 8.0
@export var JUMP_VELOCITY = 4.5
@export var SENSITIVITY = 0.001

#bobbing variables (not used)
const BOB_FREQ = 2.0
const BOB_AMP = 0.08
var t_bob = 0.0

@export var gravity = 9.8

@onready var head = $Head
@onready var camera = $Head/Camera3D
@onready var footstep = $PlayerAudio/Footstep
@onready var headbob: AnimationPlayer = $headbob

func _ready():
	Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
	
func _unhandled_input(event):
	if event is InputEventMouseMotion:
		head.rotate_y(-event.relative.x * SENSITIVITY)
		camera.rotate_x(-event.relative.y * SENSITIVITY)
		camera.rotation.x = clamp(camera.rotation.x, deg_to_rad(-40), deg_to_rad(60))

func _play_footstep_audio():
	footstep.pitch_scale = randf_range(.95, 1.05)
	if is_on_floor():
		footstep.play()

func _physics_process(delta):
	# Add the gravity.
	if not is_on_floor():
		velocity += get_gravity() * delta

	# Handle jump.
	if Input.is_action_just_pressed("jump") and is_on_floor():
		velocity.y = JUMP_VELOCITY

	 #Handle Sprint
	if Input.is_action_pressed("sprint"):
		speed = SPRINT_SPEED
	else:
		speed = WALK_SPEED
		
	var input_dir = Input.get_vector("right", "left", "back", "forward")
	var direction = (head.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
	if is_on_floor():
		if direction:
			velocity.x = direction.x * speed
			velocity.z = direction.z * speed
			headbob.play("headbob_walk")
		else:
			velocity.x = lerp(velocity.x, direction.x * speed, delta * 7.0)
			velocity.z = lerp(velocity.z, direction.z * speed, delta * 7.0)
			headbob.pause()
	else:
		velocity.x = lerp(velocity.x, direction.x * speed, delta * 3.0)
		velocity.z = lerp(velocity.z, direction.z * speed, delta * 3.0)
		headbob.pause()
	#Headbob
	#t_bob += delta * velocity.length() * float(is_on_floor())
	#camera.transform.origin = _headbob(t_bob)

	move_and_slide()

#func _headbob(time) -> Vector3:
	#var pos = Vector3.ZERO
	#pos.y = sin(time * BOB_FREQ) * BOB_AMP
	#pos.x = cos(time * BOB_FREQ/2) * BOB_AMP
	#return pos

Here’s a video of it happening:

is your SENSITIVITY export set to zero or null?

Nope, the same unfortunately

Does your headbob animation player have a Camera/Head rotation track?

Just the position track, I think it’s a scrapped animation since it’s keyframes are gone. Tried removing anything related to the headbob inside the script to see if that was the cause, but no changes.

Have you tried contacting the creator of the original script?

This was in the original script? Because that indicates the camera node must be a child of the head node to rotate on the y-axis (look left and right).

Yeah that part was in the original script, and he doesn’t really respond to youtube comments, so I can’t consult with him.

I think everything is organized properly in the player node, and the camera is parented to the head.

Try adding a print statement in your input handling code to see if you’re even getting the InputEventMouseMotion event. My guess is that you added some GUI elements to your scene, that are eating the input before your player can react to them. Try temporarily removing all GUI elements from your game that you added recently and see if this helps.
If the GUI is the issue indeed, you need to set its Mouse Behavior to Disabled.

3 Likes

I disabled the mouse behavior on my scene transition GUI and it fixed the issue, thank you

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.