Jump to content

Rotating physics problem in P2


gikdew
 Share

Recommended Posts

So, I'm developing my frist game right now, and after having lots of troubles choosing the best physics system, I think I'm going with p2, since I need circle collisions. I want to make a sprite, rotating a point, like an orbit, the problem is that when I set the anchor of that sprite, it doesnt rotate the collision body associated to it, it only rotates the image.

post-7867-0-86367800-1396358079.png
 
As you can see in the image, the phaser logo rotates, but the collision body (little debug circle), does not displace itself to the center of the sprite.
this.game.physics.p2.enable(this.sprite, true);this.sprite.body.setCircle(16);this.sprite.body.velocity.y = 100;this.sprite.body.angularVelocity = +5;this.sprite.anchor.setTo(-0.3,0.5)this.sprite.body.setZeroDamping();
Link to comment
Share on other sites

  • 2 years later...

@valueerror How can I change the anchor within a group on individual sprites...

 

  pocket_collision_group = game.physics.p2.createCollisionGroup();

  pockets = game.add.group();
  pockets.enableBody = true;
  pockets.physicsBodyType = Phaser.Physics.P2JS;
  pocket_radius = 25 * window.devicePixelRatio;

  for (var i = 0; i < 3; i++) {
    for (var j = 0; j < 2; j++) {
      var pocket = pockets.create(
                         i * game.world.width / 2,
                         game.world.height * j,
                                    'pocket');
      pocket.body.static = true;

      // This won't work. I need to adjust the pocket anchor
      // for the corners of the table, because the side pockets
      // have twice the area of the corner pockets using this code
      // pocket.body.anchor.setTo(0);

      pocket.body.clearShapes();
      pocket.body.setCircle(pocket_radius);
      pocket.body.angularVelocity = 1;
      pocket.body.setZeroDamping();
      pocket.body.setCollisionGroup(pocket_collision_group);
      pocket.body.collides([ball_collision_group,
                              flipper_collision_group]);
    }
  }

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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