Camera position resets after certain animation played

Godot Version

Ver. 4.2.1

Question

`So I’m making a game, and a problem I’ve stumbled upon is - while I made animations to crouch and uncrouch, the camera position always resets after animation is being played

And I’ve also noticed that while playing, camera resets not only position, but also rotation. I wanted to make seamless crouch system anyways

Could you record a short video of this behavior?
And please share you code (using preformatted text with ```) and node structure, so that we can better understand the status quo of your project.

The video

extends CharacterBody3D

var speed
const WALK_SPEED = 3.0
const CROUCH_SPEED = 1.5
const SPRINT_SPEED = 5.5
const JUMP_VELOCITY = 4.5
const SENSITIVITY = 0.025
@export var ANIMATIONPLAYER : AnimationPlayer

# Head bob
const BOB_FREQ = 2.8
const BOB_AMP = 0.08
var t_bob = 0.0

# Crouch
var _is_crouch : bool = false

# FOV while ruun
const BASE_FOV = 75.0
const FOV_CHANGE = 1.5

# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = 9.8

@onready var head= $"Character  Model/Head"
@onready var camera= $"Character  Model/Head/Camera3D"

#Cursor capture
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))
	if event.is_action_pressed("crouch"):
		toggle_crouch()

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

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

	# Run
	if Input.is_action_pressed("sprint"):
		speed = SPRINT_SPEED
	elif  Input.is_action_pressed("crouch"):
		speed = CROUCH_SPEED
	else:
		speed = WALK_SPEED
	
	
	
	# Get the input direction and handle the movement/deceleration.
	# As good practice, you should replace UI actions with custom gameplay actions.
	var input_dir = Input.get_vector("move_left", "move_right", "move_forward", "move_backwards")
	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
		else:
			velocity.x = lerp(velocity.x, direction.x * speed, delta * 7.5)
			velocity.z = lerp(velocity.z, direction.z * speed, delta * 7.5)
	
	else:
		velocity.x = lerp(velocity.x, direction.x * speed, delta * 3.5)
		velocity.z = lerp(velocity.z, direction.z * speed, delta * 3.5)
	#Мотание головой
	t_bob += delta * velocity.length() * float(is_on_floor())
	camera.transform.origin = _headbob(t_bob)
	
	# Сам FOV
	var velocity_clamped = clamp(velocity.length(), 0.5, SPRINT_SPEED * 2)
	var target_fov = BASE_FOV + FOV_CHANGE * velocity_clamped
	camera.fov = lerp(camera.fov, target_fov, delta * 8.0)
	
	
	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 / 1.5) * BOB_AMP
	return pos

func toggle_crouch():
	if _is_crouch == true:
		ANIMATIONPLAYER.play("uncrouch")
	elif _is_crouch == false:
		ANIMATIONPLAYER.play("crouch")
	_is_crouch = !_is_crouch

And how does your crouch animation look like? Can you share a screenshot of that?

I sent a video above the code, you should look into that vid

I did watch the video.
What I meant is for you to show us how the crouch animation setup looks like in the Animation player - what exactly and how you’re animating.

oooooh
Sorry, here ya go

Ok, I see.
The issue seems to be with the fact that you’re animating the head’s and camera’s rotation directly, and you use the same Nodes for your mouse input rotation. The animation rotation overrides the mouse input rotation. You need to either combine these rotations, or put them on separate Nodes and parent to each other, so that they don’t collide with each other.

Ok, uh, and how do I do it?
Srry if that question is kinda dumb, I’m new to godot