Jump to content

collision detection


Recommended Posts

hello guys,

Im trying to implement collision detection to my game, 

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


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

if (myGame.physics.arcade.collide(collider1, collidor2))




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







Link to comment
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:




this.physics.p2.restitution = 0.8;

var playerCollisionGroup = this.physics.p2.createCollisionGroup();
var cloudCollisionGroup = this.physics.p2.createCollisionGroup();
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);

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"


Link to comment
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..

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...