Animations stop working after the first trigger

Godot 4.4 Stable

I have a few animations that respond to keystrokes in my func _physics_process(delta: float) -> void: for crouch and jump, but they stop working after the first use. How do I go about fixing this problem? Thank you!

Link to video: https://youtu.be/_gk5EnkCU9o

Physics Process:

func _physics_process(delta: float) -> void:

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

	# Handle Start Jump.
	if Input.is_action_just_pressed("jump") and is_on_floor():
		velocity.y = JUMP_VELOCITY
		anim_tree.set("parameters/Jump/blend_amount", velocity.length() / SPEED)
	

#Handle Start Crouch
	if Input.is_action_pressed("crouch"):
		anim_tree.set("parameters/Crouch_Start/blend_amount", 1)
	if Input.is_action_just_released("crouch"):
		anim_tree.set("parameters/Crouch_End/blend_amount", 1)

	# 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("left", "right", "forward", "backward")
	var direction := (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
	direction = direction.rotated(Vector3.UP, spring_arm_pivot.rotation.y)
	if direction:
		velocity.x = lerp(velocity.x, direction.x * SPEED, lerp_val)
		velocity.z = lerp(velocity.z, direction.z * SPEED, lerp_val)
		armature.rotation.y = lerp_angle(armature.rotation.y, atan2(-velocity.x, -velocity.z), lerp_val)
		
	else:
		velocity.x = lerp(velocity.x, 0.0, lerp_val)
		velocity.z = lerp(velocity.z, 0.0, lerp_val)
		
	anim_tree.set("parameters/Run/blend_amount", velocity.length() / SPEED)

You set the animation parameters to 1.0, they never return to 0.0 and it seems you aren’t setting up your animation tree to use blend positions incorrectly if you have a seperate Crouch_Start blend and a Crouch_End blend.

Here’s an example of a blend space 2D, where the x axis is used for crouching, of which you could use a blend space 1D to achieve the same effect

Notice I move the blend position over from 0.0 to 1.0 crouch and I can move from 1.0 to 0.0 to stand back up.

If you want to change a blend position over time you can use a Tween

Here’s the same code I use for this tree, changing the value with a tween.

elif event.is_action("crouch"):
	if crouching != event.is_pressed():
		crouching = event.is_pressed()

		var crouch_tween: Tween = create_tween().set_parallel()
		var final_value: float = 1.0 if crouching else 0.0
		crouch_tween.tween_property(animator, "parameters/Idle/blend_position:x", final_value, 0.125)
2 Likes

What I am getting as that I don’t need to have a separate Standing, Crouching, or Jumping start/end animations if I have their ‘end’ states tied through blend spaces, then use events to change blend position? I’m sure I’m getting this wrong.

I know my phrasing here is rough, but I’ll take a look at some videos to help. Thank you!

You can probably achieve the effect you want from having a crouch_idle animation and a standing_idle animation, then use a blend space between them. Similarly a crouch_walk and standing_walk for a different blend space.

Thank you, I will start making that now!