Attack collision

Hello, it’s me, again. Sorry for bothering you so much, I hope you are well🙂

I have an object.

If the X key is pressed in my game I activate the body of said object since I am using it as an attack hitbox, I would like that when the attack animation ends the body of the object is deactivated but when I do this now it never collides. So if I leave the body active, the video happens. It’s supposed to collide when the player hits the enemy, so if I leave the body active, the video happens, that’s why I want to deactivate it when the animation ends.

Could someone guide me a bit?

this is my callback of collision

hitPig(mazo,pig){

    if (pig.hitsToDie == 0) {

        pig.hitsToDie=-1;

        pig.anims.play('PigMuriendo');

        //esperar un segundo y despues destruye el puerquito

        this.time.addEvent({callback: () => {pig.destroy()}, delay: 1000, callbackScope: this, loop: true})

        console.log('murio');

       

    }

    else{

        if (pig.hitsToDie>0){

            pig.hitsToDie--;

            console.log('No murio');

           

        }

    }

    mazo.body.enable = false;

}

And this is when I play the animation

else if (Phaser.Input.Keyboard.JustDown(this.ataque)){

        this.scene.physics.world.add(this.mazoHitbox.body);

        //Si el rey se voltea la hitbox tambien  

        this.mazoHitbox.x = this.scene.rey.flipX

            ? this.scene.rey.x - this.scene.rey.width * 0.1

            : this.scene.rey.x + this.scene.rey.width * 0.1

        this.mazoHitbox.y = this.scene.rey.y;

        this.anims.play('ReyAtacando',true);

}

I think you want something like

player.on('animationupdate', (anim, frame, gameObject, frameKey) => {
  if (frameKey === ATTACK) {
    hammer.body.enable = true;

    // Not sure if `body.x` or `x` will work here
    hammer.body.x = player.body.x + OFFSET;
  } else {
    hammer.body.enable = false;
  }
});