# Collision detection

**URL:** <https://phaser.discourse.group/t/collision-detection/9819>\
**Category:** Phaser 3\
**Created:** [June 21, 2021, 8:46am UTC](https://phaser.discourse.group/t/collision-detection/9819 "2021-06-21T08:46:38Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Keerti\_Jain](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/keerti_jain/32/5313_2.png) [@Keerti\_Jain](https://phaser.discourse.group/u/Keerti_Jain)\
**Post date:** [June 21, 2021, 8:46am UTC](https://phaser.discourse.group/t/collision-detection/9819/1 "2021-06-21T08:46:38Z")

</div>

Hi,  
I am new to phaser. I want to create carrom ,where striker hits a coin then all the coins collide .I could hit by striker and could set all coins to move.but all the coins continuously move with bounceX,Y value.The coins keeps on moving,the coin does not settle.can anyone help me how can I fix the problem.

---

<div class="post-metadata">

**Author:** ![Milton](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@Milton](https://phaser.discourse.group/u/Milton)\
**Post date:** [June 21, 2021, 9:29am UTC](https://phaser.discourse.group/t/collision-detection/9819/2 "2021-06-21T09:29:24Z")

</div>

Set bounce smaller than 1, add damping/drag.

---

<div class="post-metadata">

**Author:** ![Keerti\_Jain](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/keerti_jain/32/5313_2.png) [@Keerti\_Jain](https://phaser.discourse.group/u/Keerti_Jain)\
**Post date:** [June 21, 2021, 9:53am UTC](https://phaser.discourse.group/t/collision-detection/9819/3 "2021-06-21T09:53:51Z")

</div>

I have set the bounce value to .1,the coins move slowly but are not settled

---

<div class="post-metadata">

**Author:** ![Milton](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@Milton](https://phaser.discourse.group/u/Milton)\
**Post date:** [June 21, 2021, 10:10am UTC](https://phaser.discourse.group/t/collision-detection/9819/4 "2021-06-21T10:10:25Z")

</div>

```javascript
sprite.body.useDamping=true;
sprite.setDrag(0.99);///takes value between 0-1

```

---

<div class="post-metadata">

**Author:** ![Keerti\_Jain](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/keerti_jain/32/5313_2.png) [@Keerti\_Jain](https://phaser.discourse.group/u/Keerti_Jain)\
**Post date:** [June 21, 2021, 10:39am UTC](https://phaser.discourse.group/t/collision-detection/9819/5 "2021-06-21T10:39:14Z")

</div>

The coin slows down but doesn’t [settle.it](http://settle.it) keeps on moving slowly

this.physics.add.group({collideWorldBounds: true,bounceX: 0.1,  
bounceY: 0.1,damping:true,Dragx: 0.99,DragY :0.99

});

---

<div class="post-metadata">

**Author:** ![Milton](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@Milton](https://phaser.discourse.group/u/Milton)\
**Post date:** [June 21, 2021, 10:48am UTC](https://phaser.discourse.group/t/collision-detection/9819/6 "2021-06-21T10:48:39Z")

</div>

I don’t see ‘damping’ as property for a physics group config. Maybe try setting it manually.

---

<div class="post-metadata">

**Author:** ![Keerti\_Jain](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/keerti_jain/32/5313_2.png) [@Keerti\_Jain](https://phaser.discourse.group/u/Keerti_Jain)\
**Post date:** [June 21, 2021, 12:02pm UTC](https://phaser.discourse.group/t/collision-detection/9819/7 "2021-06-21T12:02:26Z")

</div>

I tried manually adding ,but it didn’t work.i found allowdrag(), but it didn’t work.

One more thing I want to know how can handle collision between group.

![image.png](https://global.discourse-cdn.com/free1/uploads/phaser1/original/2X/0/082ad34999bea78ea623081ef44693a303b0b351.png)

---

<div class="post-metadata">

**Author:** ![Milton](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@Milton](https://phaser.discourse.group/u/Milton)\
**Post date:** [June 21, 2021, 12:50pm UTC](https://phaser.discourse.group/t/collision-detection/9819/8 "2021-06-21T12:50:51Z")

</div>

Show how you did it manually? You need to iterate the group and set each body’s `useDamping=true`.

> [@Keerti\_Jain](#):
>
> One more thing I want to know how can handle collision between group.

`this.physics.add.collider(object1, object2, callback, null, this);`

object1 and object2 can be sprites/groups/layers etc.

---

<div class="post-metadata">

**Author:** ![Keerti\_Jain](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/keerti_jain/32/5313_2.png) [@Keerti\_Jain](https://phaser.discourse.group/u/Keerti_Jain)\
**Post date:** [June 21, 2021, 4:05pm UTC](https://phaser.discourse.group/t/collision-detection/9819/9 "2021-06-21T16:05:46Z")

</div>

pirateship.body.setdamping( true)  
pirateship=this.physics.add.group({collideWorldBounds: true,bounceX: 0.1,  
bounceY: 0.1,Dragx: 0.99,DragY :0.99,allowdrag:true

});

I used above code for manually setdamping

---

<div class="post-metadata">

**Author:** ![Milton](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@Milton](https://phaser.discourse.group/u/Milton)\
**Post date:** [June 21, 2021, 4:17pm UTC](https://phaser.discourse.group/t/collision-detection/9819/10 "2021-06-21T16:17:01Z")

</div>

Hmm, that’s never going to work ☹  
You can’t set a property of pirateship before you declare pirateship.  
Also, pirateship is the group, it has no body.  
Look [here](https://phaser.io/tutorials/making-your-first-phaser-3-game/part8) for an example.  
Follow tutorials before you jump in too deep…

---

<div class="post-metadata">

**Author:** ![Keerti\_Jain](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/keerti_jain/32/5313_2.png) [@Keerti\_Jain](https://phaser.discourse.group/u/Keerti_Jain)\
**Post date:** [June 21, 2021, 5:00pm UTC](https://phaser.discourse.group/t/collision-detection/9819/11 "2021-06-21T17:00:37Z")

</div>

// pirateship.body.setdamping( true)  
pirateship=this.physics.add.group(  
{key: ‘coins’,collideWorldBounds: true,  
});  
// pirateship.body.usedamp

// pirateship.setbounce(1,1)  
// pirateship.body.usedamping=true;  
pirateship.create(200,200,‘pirateShipred’);  
pirateship.create(214,200,‘pirateShipb1’);  
pirateship.create(207,214,‘pirateShipw1’);  
pirateship.create(193,186,‘pirateShipw1’);

pirateship.children.iterate(function (child) {  
child.setDraping(true)  
child.setBounceY(Phaser.Math.FloatBetween(0.4, 0.8));  
child.setBounceX(Phaser.Math.FloatBetween(0.4, 0.8));  
child.setDragX(0.99);  
child.setDragY(0.99);

});

I can see in the documentation setDraping(),but when used says undefined

---

<div class="post-metadata">

**Author:** ![Milton](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@Milton](https://phaser.discourse.group/u/Milton)\
**Post date:** [June 21, 2021, 5:03pm UTC](https://phaser.discourse.group/t/collision-detection/9819/12 "2021-06-21T17:03:01Z")

</div>

Damping, not draping…

---

<div class="post-metadata">

**Author:** ![Keerti\_Jain](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/keerti_jain/32/5313_2.png) [@Keerti\_Jain](https://phaser.discourse.group/u/Keerti_Jain)\
**Post date:** [June 21, 2021, 5:38pm UTC](https://phaser.discourse.group/t/collision-detection/9819/13 "2021-06-21T17:38:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Keerti\_Jain](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/keerti_jain/32/5313_2.png) [@Keerti\_Jain](https://phaser.discourse.group/u/Keerti_Jain)\
**Post date:** [June 21, 2021, 5:41pm UTC](https://phaser.discourse.group/t/collision-detection/9819/14 "2021-06-21T17:41:19Z")

</div>

I could resolve the error but now the coins are not moving

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

---

<div class="post-metadata">

**Author:** ![Milton](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@Milton](https://phaser.discourse.group/u/Milton)\
**Post date:** [June 21, 2021, 5:41pm UTC](https://phaser.discourse.group/t/collision-detection/9819/15 "2021-06-21T17:41:49Z")

</div>

[setDamping](https://photonstorm.github.io/phaser3-docs/Phaser.Physics.Arcade.Body.html#setDamping__anchor)

Learn how to use the documentation.

---

<div class="post-metadata">

**Author:** ![Keerti\_Jain](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/keerti_jain/32/5313_2.png) [@Keerti\_Jain](https://phaser.discourse.group/u/Keerti_Jain)\
**Post date:** [June 21, 2021, 5:50pm UTC](https://phaser.discourse.group/t/collision-detection/9819/16 "2021-06-21T17:50:54Z")

</div>

Now it is working when i child.setDamping(false).

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

---

<div class="post-metadata">

**Author:** ![Keerti\_Jain](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/keerti_jain/32/5313_2.png) [@Keerti\_Jain](https://phaser.discourse.group/u/Keerti_Jain)\
**Post date:** [June 21, 2021, 6:25pm UTC](https://phaser.discourse.group/t/collision-detection/9819/17 "2021-06-21T18:25:45Z")

</div>

Thanks for your quick response Milton

---

<div class="post-metadata">

**Author:** ![Keerti\_Jain](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/keerti_jain/32/5313_2.png) [@Keerti\_Jain](https://phaser.discourse.group/u/Keerti_Jain)\
**Post date:** [June 25, 2021, 4:41pm UTC](https://phaser.discourse.group/t/collision-detection/9819/18 "2021-06-25T16:41:46Z")

</div>

Hi Milton,

I want to handle two consecutive mouse click  
a) on first click ,stricker should move to the mouse position  
b) on second click,stricker should hit the coin ie the new mouse position.

here the stricker is placed but the stricker does not hit the coin  
here is my code update(){

if(strickerPos==false)  
{

if(mouse.isDown&& control==false)  
{  
console.log(“indown”)  
strickerball.x +=(input.x-strickerball.x);  
strickerPos==true;  
}

}  
else{  
if(mouse.isDown&& control==false ){  
console.log(“second play”)  
let angle=Phaser.Math.Angle.Between(strickerball.x,strickerball.y,input.x,input.y);  
//rotation cannon with PI/2  
strickerball.setRotation(angle+Math.PI/2);  
this.physics.moveTo(strickerball,input.x,input.y,500);  
strickerPos=false;  
control=true;  
}  
// strickerPos=true;  
//}

//check world bounds  
if((strickerball.x\>/_worldBounds.width_/400 )||  
(strickerball.y\>/_worldBounds.height_/400) ||  
strickerball.x\<0 ||  
strickerball.y\<0){  
control=false;  
}

//for collision  
// this.physics.add.overlap(strickerball,pirateship,destroy,null,this);  
// this.physics.collide(strickerball,pirateship)  
[//this.physics.collide](https://this.physics.collide)(strickerball,[pirateship])  
this.physics.add.collider(strickerball, pirateship);  
this.physics.add.collider(pirateship,pirateship);  
}

}

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

---

<div class="post-metadata">

**Author:** ![Milton](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@Milton](https://phaser.discourse.group/u/Milton)\
**Post date:** [June 25, 2021, 5:10pm UTC](https://phaser.discourse.group/t/collision-detection/9819/19 "2021-06-25T17:10:00Z")

</div>

You’ll have to be more specific 🙂

Be aware that Phaser doesn’t have Continuous Collision Detection, so fast moving objects often ‘tunnel’, skipping collision altogether…

See [here](https://codepen.io/steveeeie/details/zjYmjR).

---

<div class="post-metadata">

**Author:** ![Keerti\_Jain](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/keerti_jain/32/5313_2.png) [@Keerti\_Jain](https://phaser.discourse.group/u/Keerti_Jain)\
**Post date:** [June 28, 2021, 5:53pm UTC](https://phaser.discourse.group/t/collision-detection/9819/20 "2021-06-28T17:53:09Z")

</div>

Hi milton,

why am i getting this rectangular box at the starting coordinates of world bounds  
this.physics.world.bounds.setTo(60, 60, 380,380);  
how can i remove it?

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

[Next page](https://phaser.discourse.group/t/collision-detection/9819.md?page=2)
