#Animation switching glitch

1 messages · Page 1 of 1 (latest)

frigid scroll
#

I'm trying to switch the animations of the scorpion between idle and attack, but as you can see whenever the attack starts it like does a super fast one before it. I've tried calling it with a function, but I've also tried using the animation finished signal. The animations look fine when I play them in the editor.

sour oak
# frigid scroll I'm trying to switch the animations of the scorpion between idle and attack, but...

go to the editor and make sure that in the animation player, the animation is set on the first frame. The code seems fine but make sure that the animation is selected on the first frame. If its not selected in the first frame on the editor then it will practicaly start the animation from where you selected it.

But ive noticed you use an animation player for its attack. It might be better to use an animated_sprite_2d node for this. Because it works simpler and it might solve this issue in one go.
I would use the animationplayer to make certain objects move around in a patern but for idle and actual animations it might be better to use animated sprite.

If you need help with the code work ill be happy to instruct you.

frigid scroll
#

I'd definitely prefer to use animated_sprite_2d, but then I wasn't able to add a hitbox that would work with the animation (activates when attack hits). I also intend to add parrying mechanics. Would this be possible using it instead of animation player?

sour oak
#

What you could is the following. You already add the hitbox for the attack. So the hitbox is always there. But you put the collision to disabled and the moment the attack animation starts you do this; (name of collision node).disabled = true. And then you can do an await animated_sprite.animation_finished and then add the same line of code under it but then set it to false instead of true.

You can try to do this method or use the animated sprite for the scorpion attack animation and use an animation player for just its collision shape

frigid scroll
#

ok thanks, I'll try those options and update here if I'm having issues

sour oak
#

Sure thing

frigid scroll
#

I've tried moving the disabled line around and switch false and true, but I can't seem to be able to figure it out. Here's the code in case you can spot the issue?


@onready var anim_sprite: AnimatedSprite2D = $AnimatedSprite2D
@onready var attack_area: Area2D = $AttackArea
@onready var attack_shape: CollisionShape2D = $AttackArea/hitbox

var attack_interval := 4.0
var attack_timer := 0.0
var is_attacking := false

func _ready():
    anim_sprite.play("idle")


func _process(delta):
    if is_attacking:
        return

    attack_timer += delta
    if attack_timer >= attack_interval:
        attack_timer = 0.0
        start_attack()

func start_attack():
    is_attacking = true
    attack_shape.disabled = true
    anim_sprite.play("attack")
    await anim_sprite.animation_finished
    attack_shape.disabled = false


func _on_attack_area_area_entered(area: Area2D) -> void:
    if area.name == "PlayerHitbox" and area.get_parent().has_method("die"):
        area.get_parent().die()


func _on_animated_sprite_2d_animation_finished() -> void:
        if anim_sprite.animation == "attack":
            is_attacking = false
            anim_sprite.play("idle")
sour oak
#

By saying disabled = true you disable the collision. making it uncollidable and when saying disabled = false you enable the collision again. allowing it to collide. maybe that the little issue thats accuring

frigid scroll
#

So you mean switching it like this? This doesn't work either tho

func start_attack():
is_attacking = true
attack_shape.disabled = false
anim_sprite.play("attack")
await anim_sprite.animation_finished
attack_shape.disabled = true

#

oh I figured it out, forgot to link the area entered signal

#

thanks for your help!