Godot Version
Godot Version 4.4.1
Question
I’m using a node based finite state machine for my character movement, so i have each state handle it’s own inputs and i have the camera be handled by a central player script, which should always be active no matter the state. But when i press an input (i.e WASD) then moving the mouse doesn’t move the camera anymore.
What could be causing this?
Player camera script:
func _input(event: InputEvent) -> void:
# Check if mouse in window
if event.is_action_pressed("leftClick"):
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
if event.is_action_pressed("exit"):
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
func _unhandled_input(event: InputEvent) -> void:
# get mouse position
if event is InputEventMouseMotion and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
cameraInputDir = event.relative * mouseSensitivity
func _physics_process(delta: float) -> void:
## Camera
cameraPivot.rotation.x += cameraInputDir.y * delta
cameraPivot.rotation.x = clampf(cameraPivot.rotation.x, -tiltLimit, tiltLimit)
cameraPivot.rotation.y -= cameraInputDir.x * delta
cameraInputDir = Vector2.ZERO
move_and_slide()
Run state:
func Physics_Update(delta: float):
var dir := Input.get_vector("Left", "Right", "Forward", "Back")
var forward := player.camera.global_basis.z
var right := player.camera.global_basis.x
# Calculate move direction
var moveDir := forward * dir.y + right * dir.x
moveDir.y = 0.0
moveDir = moveDir.normalized()
if moveDir.length() != 0:
player.lastDir = moveDir
if dir == Vector2.ZERO:
Transitioned.emit(self, "Idle")
if player.is_on_floor() and Input.is_action_just_pressed("Jump"):
Transitioned.emit(self, "Jump")
if not player.is_on_floor():
Transitioned.emit(self, "Fall")
The other states all look very similar and basically use the same code for inputs