Sign in to follow this  
Zackorz

collision detection

Recommended Posts

hello guys,

Im trying to implement collision detection to my game, 

// i Activate the physics system in my "create" function:

 myGame.physics.startSystem(Phaser.Physics.P2JS);
 myGame.physics.p2.setImpactEvents(true);



// Now im defining the "colliding" objects in my "update" function:



if (myGame.physics.arcade.collide(collider1, collidor2))
{
  console.log("collision");
}

 

 

 

What is missing/ what im doing wrong? I never get any collision feedback, when the objects touch each other.

 

 

 

 

 

 

Share this post


Link to post
Share on other sites
5 hours ago, lukaMis said:

You are starting P2JS physics system and than checking for collide with arcade physics system. You can only have one system active in Phaser. 

Ok thanks. I tried it with " P2JS" now, but i cant figure out what im doing wrong. 

 

Here is my code:

 

 

create:



this.physics.startSystem(Phaser.Physics.P2JS);
this.physics.p2.setImpactEvents(true);
this.physics.p2.restitution = 0.8;

var playerCollisionGroup = this.physics.p2.createCollisionGroup();
var cloudCollisionGroup = this.physics.p2.createCollisionGroup();
this.physics.p2.updateBoundsCollisionGroup();
			
			
var clouds = this.add.group();
clouds.enableBody = true;
clouds.physicsBodyType = Phaser.Physics.P2JS;
			
var smallcloud= clouds.create(300, 300, 'Cloudpicture');
smallcloud.body.setRectangle(40, 40);
smallcloud.body.setCollisionGroup(cloudsCollisionGroup);
			

bird = this.add.sprite(this.world.centerX, this.world.centerY/1.5, "mysprite");
bird.anchor.setTo(0.5, 0.5);
			
bird.enableBody = true;
bird.physicsBodyType = Phaser.Physics.P2JS;
bird.body.setCollisionGroup(playerCollisionGroup); // here i get an error: "cannot read property CollisionGroup of null"




What is wrong with this line ? I think i programmed it like in the phaser "group collision example"

 

Share this post


Link to post
Share on other sites

i added: 

this.physics.p2.enable(bird, false);

 

now its working, but this line destroys all movement of my bird. I have a "tween" movement on my bird, that is triggered when i click somewhere. 

 

Why is this gone now???

 

The rest of my game is also broken , both physics objects are flying around like crazy now..

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.