# How to collide once per box in phaser 3

**URL:** <https://phaser.discourse.group/t/how-to-collide-once-per-box-in-phaser-3/10525>\
**Category:** Phaser 3\
**Created:** [October 26, 2021, 7:30pm UTC](https://phaser.discourse.group/t/how-to-collide-once-per-box-in-phaser-3/10525 "2021-10-26T19:30:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DevGame](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/devgame/32/5690_2.png) [@DevGame](https://phaser.discourse.group/u/DevGame)\
**Post date:** [October 26, 2021, 7:30pm UTC](https://phaser.discourse.group/t/how-to-collide-once-per-box-in-phaser-3/10525/1 "2021-10-26T19:30:19Z")

</div>

Hello, I am reviving the super mario game and I want to do the animation of the box, the problem is that when I collide with the box for the second time it continues to apply the tweens. How can I collide only once per box?

code here: [https://codepen.io/DevGame/pen/OJjmgwR?editors=1010](https://codepen.io/DevGame/pen/OJjmgwR?editors=1010)

---

<div class="post-metadata">

**Author:** ![StinOfSin](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/stinofsin/32/5625_2.png) [@StinOfSin](https://phaser.discourse.group/u/StinOfSin)\
**Post date:** [October 26, 2021, 10:59pm UTC](https://phaser.discourse.group/t/how-to-collide-once-per-box-in-phaser-3/10525/2 "2021-10-26T22:59:19Z")

</div>

Do you mean, after jumping and colliding with the box once, you want the question mark box to not play the bouncing tween when you hit it again?

If I understand it correctly, you’ll have to find some way to manage the state of each block. I think the data manager component would work fine here.

```javascript
create() {
  ...
  // after defining your physics group 'cuestion'
  cuestion.getChildren().forEach( box => {
    // enable the data manager component for each box in the group
    box.setDataEnabled();
    // initialize a data variable to each box to see if it's been hit yet
    box.data.set('hit', false);
  });

  // Inside your 'impact' collider callback function
  impact(player, cuestion) {
    if (
      player.body.touching.up &&
      !player.body.touching.down &&
      !cuestion.data.get('hit') // Add a check to see if this box has been hit
    ) {
      this.tweens.add({
        targets: cuestion,
        y: 220,
        duration: 100,
        yoyo: true,
        onStart: () => { console.log("IMPACT") },
        onComplete: () => { box.data.set('hit', true) }, // set box as hit when first hit
      });
    }
  }
}

```

You could also change the texture of the box to a blank “used” box in the tween’s onComplete callback function.

---

<div class="post-metadata">

**Author:** ![DevGame](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/devgame/32/5690_2.png) [@DevGame](https://phaser.discourse.group/u/DevGame)\
**Post date:** [October 27, 2021, 8:47pm UTC](https://phaser.discourse.group/t/how-to-collide-once-per-box-in-phaser-3/10525/3 "2021-10-27T20:47:30Z")

</div>

Thanks, that’s exactly what I wanted 🙂
