#My Animation Isn't Working

1 messages · Page 1 of 1 (latest)

timid zenith
#

This happens a lot and I dont know how to fix it. The animation only plays when the player is walking towards the right, and I want the animation to play whenever the player walks at all.

#

""extends CharacterBody2D

@onready var animated_sprite = $AnimatedSprite2D

const SPEED = 50
var directionan = 0

func _physics_process(delta):
if Input.is_action_pressed("w"):
position.y += -SPEED * delta
else:
directionan = 0
animated_sprite.flip_h = false
if Input.is_action_pressed("s"):
position.y += SPEED * delta
directionan = 1
else:
directionan = 0
animated_sprite.flip_h = false
if Input.is_action_pressed("a"):
position.x += -SPEED * delta
directionan = 1
animated_sprite.flip_h = true
else:
directionan = 0
animated_sprite.flip_h = false
if Input.is_action_pressed("d"):
position.x += SPEED * delta
directionan = 1
animated_sprite.flip_h = false
else:
directionan = 0
animated_sprite.flip_h = false
if directionan == 1:
animated_sprite.play("Walking")
if directionan == 0:
animated_sprite.play("Idle")""

young whale
#

All of the else statements are run regardless of what button youre pressing , so its setting directionan to 0 everytime, since walking right is the last statement, it will set it to 1 correctly. Try using an elif statement instead so only one press is allowed at once.