wayfinder Posted June 6, 2014 Share Posted June 6, 2014 Hey there! I'm trying to wrap my head around collisiongroups in p2 at the moment, and I am hitting a wall. I can set up my game without collisiongroups, then my player will collide with all objects (only the ground for now) in the world, but try as i might, i can't get it to collide with the world bounds. OR i can set it up with collisiongroups (one for the player, one for my ground), then the player WILL collide with the world bounds, but not with the ground any more. I have no idea why, the world bounds example is so simple and yet when i try to do something similar, it just doesn't work! I have to confess, I don't *get* CollisionGroups yet. Is there a document that talks about best practises and the general concepts somewhere? the examples are really quite opaque to me he;lp Link to comment Share on other sites More sharing options...
wayfinder Posted June 7, 2014 Author Share Posted June 7, 2014 Does anybody know anything about this? I can't get my stuff to collide ;( Link to comment Share on other sites More sharing options...
lewster32 Posted June 7, 2014 Share Posted June 7, 2014 I believe this may be of help - it looks like collisionGroup is based on Box2D's implementation. Link to comment Share on other sites More sharing options...
wayfinder Posted June 7, 2014 Author Share Posted June 7, 2014 yeah, i read that earlier today, but i can't seems to get phaser to agree with me on what should be happening I set up my player to collideWorldBounds, and he doesn't I set up my player to collide with my level collisiongroup, and my level to collide with my player collisiongroup, and they don't This is a little frustrating Link to comment Share on other sites More sharing options...
wayfinder Posted June 7, 2014 Author Share Posted June 7, 2014 update: i can let my player collide with the world bounds if i comment out the line that assigns him to a collisiongroup.. maddening edit: update 2: if I remove the line that assigns a collisiongroup to my level, a separate sprite that has no collisiongroup set will collide with it. not, however my player? why. argh. edit: update 3: if I remove the body.collides on my player, it will collide with the level, but not any more with the bounds. i feel like i'm driving a clown car Link to comment Share on other sites More sharing options...
wayfinder Posted June 7, 2014 Author Share Posted June 7, 2014 Another update: by moving the setBoundsToWorld instruction before the sprite collisiongroup assignment, I have now created a situation where my player (assigned a collisiongroup and collideswith set to contain the level) collides with the world bounds (yay!) but not the level (boo!). the level has a collisiongroup assigned and collideswith contains the player collisiongroup. Is there a way to access the CollisionMask directly(other than via collides()? Link to comment Share on other sites More sharing options...
Zef Posted June 8, 2014 Share Posted June 8, 2014 I don't know if this is still why you ware having problems, but it definitely was to begin with. Take a close look at this straight from the examples // Create our collision groups. One for the player, one for the pandasvar playerCollisionGroup = game.physics.p2.createCollisionGroup();var pandaCollisionGroup = game.physics.p2.createCollisionGroup();// This part is vital if you want the objects with their own collision groups to still collide with the world bounds// (which we do) - what this does is adjust the bounds to use its own collision group.game.physics.p2.updateBoundsCollisionGroup(); Link to comment Share on other sites More sharing options...
wayfinder Posted June 8, 2014 Author Share Posted June 8, 2014 Yeah.. and it turns out my scenery shapes had the wrong collisiongroup set I was treating setCollisionGroup as an attribute instead of a method in that one call... that kept me busy until just now, with impossible-to-extrapolate-from behavior. I'm writing this down as much for my own memory as for maybe anyone else looking for information who happens to stumble on this thread: collisiongroups: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 (bounds collisiongroup, decimal: 2) 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 (player collisiongroup, decimal: 4) 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 (enemy collisiongroup, decimal: 8) 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 (scenery collisiongroup, decimal 16)-------------------------------------------- collision masks 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 (zero mask: Will collide with nothing) 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 (player mask: will collide with scenery, enemy and bounds: 16 + 8 + 2 = 26) 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 (bounds mask: will collide with players and enemies: 8 + 4 = 12) and once again, a stupid bug in my code kept me tinkering for two days Link to comment Share on other sites More sharing options...
wayfinder Posted June 8, 2014 Author Share Posted June 8, 2014 To Phaser's credit, its system is a lot easier than working with the raw masks – if you don't accidentally write setCollisionGroup = x instead of setCollisionGroup(x) Link to comment Share on other sites More sharing options...
wayfinder Posted June 8, 2014 Author Share Posted June 8, 2014 EXCEPT! I think there's a bug in there where the everythingCollisionGroup defaults to 2147483648 (1000 0000 0000 0000 0000 0000 0000 0000) instead of -1 (1111 1111 1111 1111 1111 1111 1111 1111) ...or maybe that's smart thinking and lets you do bitwise "everything but" masks? Link to comment Share on other sites More sharing options...
Recommended Posts