Walk animation works only plays the first frame when facing other directions

v 4.2.2

when my character idles or walks facing fowards the animations play as intended but when facing the other directions it only plays the first frame then stops

It’s hard to tell without more info but sometimes this happens because you call play() on the animation every frame, so it gets reset every frame, or soemthing like that…

Could you post some code that controls the walk, animation and stuff?

sorry im new to godot and the forum so when i was trying to send the code i accidentally posted and didnt know how to undo
heres the script tho:

extends CharacterBody2D

enum Facing {Front, Back, Left, Right}
enum MovementState {Idle, Moving}

var current_facing = Facing.Front
var current_movestate = MovementState.Idle

@onready var animated_sprite_2d: AnimatedSprite2D = $AnimatedSprite2D

var speed = 30

func _physics_process(_delta):
	var direction = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
	velocity = direction * speed
	if Input.is_action_pressed("ui_left"):
		current_facing = Facing.Left
		current_movestate = MovementState.Moving
	if Input.is_action_pressed("ui_right"):
		current_facing = Facing.Right
		current_movestate = MovementState.Moving
	if Input.is_action_pressed("ui_up"):
		current_facing = Facing.Back
		current_movestate = MovementState.Moving
	if Input.is_action_pressed("ui_down"):
		current_facing = Facing.Front
		current_movestate = MovementState.Moving
	else:
		current_movestate = MovementState.Idle
	
	match current_movestate:
		MovementState.Idle:
			match current_facing:
				Facing.Left: animated_sprite_2d.play("LeftIdle")
				Facing.Right: animated_sprite_2d.play("RightIdle")
				Facing.Back: animated_sprite_2d.play("BackIdle")
				Facing.Front: animated_sprite_2d.play("FrontIdle")
		
		MovementState.Moving:
			match current_facing:
				Facing.Left: animated_sprite_2d.play("LeftWalk")
				Facing.Right: animated_sprite_2d.play("RightWalk")
				Facing.Back: animated_sprite_2d.play("BackWalk")
				Facing.Front: animated_sprite_2d.play("FrontWalk")
	move_and_slide()
1 Like

You have to change these if statements to elif like I did above, otherwise the else at the bottom will always run (when you’re not pressing down) and sets the movestate to idle.

thank you this fixed it!! ^^

1 Like

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