Godot Version
4.2.1
Question
My Animation Player keeps playing its on load animation (its spawning animation) twice when I only want it to play once. The animation is not called in the Node’s script at all so I am a bit lost on why its playing twice. This is the script here for context but again the animation is set to autoplay on load so its not called in the script.
func _ready():
set_physics_process(false)
$Hurtbox.area_entered.connect(_on_area_entered)
set_target()
func _physics_process(_delta):
direction = position.direction_to(randomPlayer.global_position)
var distance = position.distance_to(randomPlayer.position)
if distance <= attackRange:
$AnimationPlayer.play("attack")
velocity = velocity.lerp(Vector2.ZERO, friction)
else:
$AnimationPlayer.play("run")
velocity = velocity.lerp(direction.normalized() * speed, acceleration)
if direction.x > 0:
$Sprite2D.scale.x = -1
else:
$Sprite2D.scale.x = 1
move_and_slide()
if health <= 0:
die()
func _on_animation_player_animation_finished(anim_name):
if anim_name == "spawn":
$AnimationPlayer.play("run")
set_physics_process(true)