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.
Set bounce smaller than 1, add damping/drag.
I have set the bounce value to .1,the coins move slowly but are not settled
sprite.body.useDamping=true;
sprite.setDrag(0.99);///takes value between 0-1
The coin slows down but doesnât 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
});
I donât see âdampingâ as property for a physics group config. Maybe try setting it manually.
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.
Show how you did it manually? You need to iterate the group and set each bodyâs useDamping=true
.
this.physics.add.collider(object1, object2, callback, null, this);
object1 and object2 can be sprites/groups/layers etc.
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
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 for an example.
Follow tutorials before you jump in too deepâŚ
// 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
Damping, not drapingâŚ
Learn how to use the documentation.
Thanks for your quick response Milton
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(strickerball,[pirateship])
this.physics.add.collider(strickerball, pirateship);
this.physics.add.collider(pirateship,pirateship);
}
}
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.
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?