Healing animation not playing

Godot Version

v4.4.1 stable.official

Hello,

I am creating a healing script for my game. The fx appear, however the player animation does not play. This also applies for the other spell I have. I am extremely confused. This is my code. The spells take effect particularly in the func _input area and the beginning.

`extends CharacterBody2D

@onready var animatedSprite = $AnimatedSprite2D
@onready var Fireball = preload(“res://tscnFolder/fireball.tscn”)
@onready var heal=preload(“res://tscnFolder/heal_body.tscn”)

@export var health = 100
@export var mana = 100
@export var speed=200

func _velocityControl():
if velocity.y>0:
velocity.y-=1
elif velocity.y<0:
velocity.y+=1
if velocity.x>0:
velocity.x-=1

func _ready() → void:
position = Vector2(0,0)

func move():
var input_direction = Input.get_vector(“Left”,“Right”,“Up”,“Down”)
if input_direction:
$AnimatedSprite2D.play(“walking”)
else:
$AnimatedSprite2D.play(“idle”)
velocity = input_direction * speed

func _input(event):
if event.is_action_pressed(“Spellcast_1”):
var newFireball = Fireball.instantiate()
add_child(newFireball)
newFireball.transform = transform
animatedSprite.play(“spellcasting”)
if event.is_action_pressed(“Spellcast_2”):
var newHeal = heal.instantiate()
add_child(newHeal)
newHeal.position = position
animatedSprite.play(“heal”)
health+=33.34
if event.is_action_pressed(“Escape”):
position.x = 71.0
position.y = -256

func _process(delta: float) → void:
_velocityControl()
look_at(get_global_mouse_position())
move()
move_and_slide()`

move() is constantly playing either “walking” or “idle” animation, so the spell animations get immediately overwriten by them.

How could I fix this without halting movement? Some spells would be ok without movement, but with others it would make the game feel slow and choppy.

Update: I ended up fixing it by making a boolean variable to check if a spell was being cast or not. The variable would disable all animations but the spellcasting one, then use an await function to allow animations to play after the spell was done. Thank you for your help.

1 Like