# Different collision box for player sprite and weapon sprite

**URL:** <https://phaser.discourse.group/t/different-collision-box-for-player-sprite-and-weapon-sprite/11920>\
**Category:** Phaser 3\
**Created:** [June 25, 2022, 2:14pm UTC](https://phaser.discourse.group/t/different-collision-box-for-player-sprite-and-weapon-sprite/11920 "2022-06-25T14:14:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![felix2000jp](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/felix2000jp/32/6662_2.png) [@felix2000jp](https://phaser.discourse.group/u/felix2000jp)\
**Post date:** [June 25, 2022, 2:14pm UTC](https://phaser.discourse.group/t/different-collision-box-for-player-sprite-and-weapon-sprite/11920/1 "2022-06-25T14:14:00Z")

</div>

So I have been messing with Phaser 3 and for my second game wanted to try doing a simple dungeon crawler to get experience with combat and collision boxes.

What I have is a sprite with a knight and an image of sword and want to build an object that combines the two. It is however important that they have different collision boxes. I have looked around and I see that containers are recommended when trying to attach sprites so I tried them but they don’t seem to allow for two different collision boxes.

I have come up with a solution for this by creating my own custom game object:

![player](https://global.discourse-cdn.com/free1/uploads/phaser1/original/2X/6/6e6ef2272cdc79408eedd31826469926765e219b.png)

![knight](https://global.discourse-cdn.com/free1/uploads/phaser1/original/2X/2/2bafd27efdf5288a90076f40c3d6702a499d1876.png)

![weapon](https://global.discourse-cdn.com/free1/uploads/phaser1/original/2X/2/2c1035696a70717fa17d4baca2bcf9e7a1afc2bf.png)

 ![result](https://global.discourse-cdn.com/free1/uploads/phaser1/original/2X/5/5f321231387edf664efb79149cb1cffa4e199cf6.png)

I do wonder if this is just and over-complicated solution. Is this the way to go or have I missed some kind of feature that allows me to do exactly what I want here.

Also, by the way, what is the **type** variable that is asked by the GameObject super method?

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [June 28, 2022, 4:02pm UTC](https://phaser.discourse.group/t/different-collision-box-for-player-sprite-and-weapon-sprite/11920/2 "2022-06-28T16:02:57Z")

</div>

I think you can do this with a physics-enabled container and children.

The `type` argument and property is used internally. But you probably shouldn’t extend `Phaser.GameObjects.GameObject` by itself.

---

<div class="post-metadata">

**Author:** ![felix2000jp](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/felix2000jp/32/6662_2.png) [@felix2000jp](https://phaser.discourse.group/u/felix2000jp)\
**Post date:** [June 28, 2022, 4:26pm UTC](https://phaser.discourse.group/t/different-collision-box-for-player-sprite-and-weapon-sprite/11920/3 "2022-06-28T16:26:13Z")

</div>

I find dealing with containers to be quite confusing. A container can have a body (collision box), I use that as the player sprite body. Now I need a new collision box that would turn on when I attacked with my sword and I am not quite sure how I would go about that. I tried looking for examples of action oriented games on phaser but did not find much besides long distance combat (bullets and other kind of projectiles). Looking at the examples perhaps phaser is not the tool for this kind of games…

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [June 28, 2022, 5:56pm UTC](https://phaser.discourse.group/t/different-collision-box-for-player-sprite-and-weapon-sprite/11920/4 "2022-06-28T17:56:53Z")

</div>

You can toggle the `body.enabled` of the sword (and also `visible`) when the attack starts and ends.
