• Content count

  • Joined

  • Last visited

  1. P2 physics child bug?

    I don't think that physics and parent-child hierarchy are generally something to be avoided, since 1) it works fine with arcade physics and 2) the function itself even has the option to handle all the children with the same body ... "enable(object [, debug] [, children])" ... (I've tried that too but it does not change anything). I have the feeling that there is simply some sprite.x, sprite.y call that should be a sprite.world.x, sprite.world.y call
  2. P2 physics child bug?

    I thought the whole point of adding children to something is that I don't have to manually set all the follow-position, follow-rotation, kill-on-parent-death stuff myself ... are you saying we just simply should not use children with P2 physics?
  3. P2 physics child bug?

    I've played around with P2 physics and created a sprite that has a child attached that can (is supposed to) move freely around the parent. The child should still contribute to collisions with other objects so I gave it a P2 body as well, but it was behaving very odd. A closer look at the debug data revealed that the collision shape and the sprite image are not at the same position o_O in fact the collision shape is located at an absolute position in the world that relates to the relative coordinates between parent and child and does not move at all. Here is an example that you can try with the sandbox editor: game.physics.startSystem(Phaser.Physics.P2JS); var parent = game.add.sprite(200, 200, 'phaser'); game.physics.p2.enable(parent, true); parent.anchor.set(0.5); var child = game.make.sprite(100, 100, 'phaser'); game.physics.p2.enable(child, true); child.body.static = true; child.anchor.set(0.5); child.angle = 0; parent.addChild(child); If you look at the attached image you can see the offset. When dragging the parent around with the mouse the collision shape will stay at a fixed position, but it CAN collide with the parent. This issue might be related to an older discussion: Any ideas how we can fix this (that don't involve creating the child as a "free" sprite and let it follow the parent via the update() function)?
  4. P2 - rotate to velocity?

    About the angle I think you can get it via the arcus tangens of the velocity or some variation of that (maybe some offset) :-) assuming of cause that your arrow is flying the right path (due to initial speed and gravity) just the sprite rotation was missing. Note: it will be radians so you can set sprite.body.rotation (not angle) with it. [UPDATE]: This should work: sprite.body.rotation = Math.atan(sprite.body.velocity.y/sprite.body.velocity.x)+Math.PI/2 [UPDATE2]: Actually it is a bit more complicated due to the nature of the arcus tanges since it depends on the direction your arrow is flying to. Your offset will need to be set by some if-then decision. The formular on the top should work for arrows that fly to the right ... I guess (hope^^).
  5. P2 collision groups exceptions

    [UPDATE] Something I found in one of the P2 examples that might be the solution I was looking for //apply a filter before the narrow collision check starts game.physics.p2.setPostBroadphaseCallback(filterCollisions, this); //use a custom "ownerId" value to check if both come from the same entity (player/npc) function filterCollisions(p2BodyA, p2BodyB) { if (p2BodyA && p2BodyB && p2BodyA.sprite.ownerId && p2BodyB.sprite.ownerId){ if (p2BodyA.sprite.ownerId == p2BodyB.sprite.ownerId){ return false; } } return true; }
  6. P2 collision groups exceptions

    Hi everybody, I'm working on my first Phaser based game and so far it's really a lot of fun One thing that keeps giving me some headaches from time to time though is that P2 physics is mostly incompatible with arcade and many tutorials only work with arcade. That seems to start with the sprite bitmaps where everything is rotated 90 degrees Usually I find some workarounds or I've replaced stuff completely like the Weapon plugin, but now I'm facing an issue with collisions where I'm not quite sure what's the best solution: Let's assume we have 2 player sprites and 2 enemy sprites and each of them has some bullets to fire. So we create 2 collision groups for the sprites and 2 for the bullets: var playerCG = game.physics.p2.createCollisionGroup(); var enemyCG = game.physics.p2.createCollisionGroup(); var playerBulletsCG = game.physics.p2.createCollisionGroup(); var enemyBulletsCG = game.physics.p2.createCollisionGroup(); player1.body.setCollisionGroup(playerCG); player1.body.collides([enemyCG, enemyBulletsCG]); p1Bullets.body.setCollisionGroup(playerBulletsCG); p1Bullets.body.collides([enemyCG]); player2.body.setCollisionGroup(playerCG); player2.body.collides([enemyCG, enemyBulletsCG]); p2Bullets.body.setCollisionGroup(playerBulletsCG); p2Bullets.body.collides([enemyCG]); enemy1.body.setCollisionGroup(enemyCG); enemy1.body.collides([playerCG, playerBulletsCG]); e1Bullets.body.setCollisionGroup(enemyBulletsCG); e1Bullets.body.collides([playerCG]); enemy2.body.setCollisionGroup(enemyCG); enemy2.body.collides([playerCG, playerBulletsCG]); e2Bullets.body.setCollisionGroup(enemyBulletsCG); e2Bullets.body.collides([playerCG]); So far so good, that works fine. But now we want to change the play-mode and want to activate "friendly fire" and "friendly collisions". If we add the playerBulletsCG to player1.body.collides(...) and playerCG to p1Bullets.body.collides(...) we get a problem when the bullets are fired from withing the collision box of a player because the players own bullets collide now with his sprite :-( Obviously we could create additional groups like player1CG, player2CG and player1BulletsCG, player2BulletsCG, but then we also have to add all these groups to the enemies and we need to come up with a whole new structure of initializing all these groups in case we want to support 4 players or more. So I was wondering if there is any method that says "collide with anything but your own bullets"? I'm open for any suggestions :-)
  7. [BUG]? - P2 Physics - nested sprites - weird behaviour

    Has there been any solution for this? It seems the child collision body is placed in the world due to the its relative coordinates to the parent. So when I add a child at 0,0 relative to the parent it shows up at worldX=0, worldY=0 when P2 physics is active.