Why is my animation constantly starting to play?

Godot Version

Godot 4.5.1 stable

Question

Why is my animation constantly starting instead of playing?

extends CharacterBody2D


var speed = 50.0;
var jump_vel = -170.0;
var crouching = false;

@onready var anims = $animations;

func _physics_process(delta: float) -> void:
	#gravity
	if not is_on_floor():
		velocity += get_gravity() * delta;
		
	#jump.
	if Input.is_action_pressed("jump") and is_on_floor():
		velocity.y = jump_vel;
	
	#walk
	var direction := Input.get_axis("left", "right")
	if direction:
		velocity.x = direction * speed;
	else:
		velocity.x = move_toward(velocity.x, 0, speed);
	
	if Input.is_action_pressed("down"):
		crouching = true;
		speed = 30;
		jump_vel = -70;
	else:
		crouching = false;
		speed = 50;
		jump_vel = -170;
	
	#animate
	
	if velocity.x > 0:
		anims.play("walk");
		$Sprite2D.flip_h = false;
	elif velocity.x < 0:
		anims.play("walk");
		$Sprite2D.flip_h = true;
	if velocity.x == 0:
		anims.play("idle");
		
	if crouching:
		if velocity.x > 0:
			anims.play("crouch_walk");
			$Sprite2D.flip_h = false;
		elif velocity.x < 0:
			anims.play("crouch_walk");
			$Sprite2D.flip_h = true;
		if velocity.x == 0:
			anims.play("crouch_stand");
	
	if not is_on_floor() and not crouching:
		anims.play("fall");
	
	move_and_slide()

Check the animating is not on loop in animation player ?

And change to a state machine


enum. states {normale,inair,jump,onrope}

    var state : int  = states.normal

match. state:

                   states.normal: #get input for walk run etc
                    If jumpButtonPressed:
                        state = states.inair

                     inair: #pressed jump
                             If is_on_ground()
                                    state = state.normal  
                       
1 Like

it is on loop
its constantly here

thanks

Yes look at the blue repete on the right look at the filter track at end see the blue highlight

1 Like

yeah, thanks a lot man! i’ve should of did that in the first place