Jump to content

Phaser P2 Physics going weird?


Teonnyn
 Share

Recommended Posts

I'm not sure what's happening here, but I'm trying to establish a basic P2 world with Phaser. However, despite essentially copying the basic settings, my test sprite keeps pulling to the -right-, as if there was horizontal gravity acting on it. The sprite is generated from an object, but mostly to contain some functions. It's anchor is set to center, and nothing else ought to be acting on it.

Here's a short clip of how it's behaving with nothing but default configuration. It ought to be falling straight down, but it is not:

https://i.gyazo.com/9bbcf69b6c7fb1e8a65fe3b4b1f676f6.mp4

  Here is the code for P2:

    game.physics.startSystem(Phaser.Physics.P2JS);
    game.stage.disableVisibilityChange = true;
    game.physics.p2.gravity.y = 80;
    game.physics.p2.applyGravity = true;    

And on the sprite itself: 

    Phaser.Sprite.call(this, game, X, Y, 'ball');
    game.physics.p2.enable(this);
    this.body.damping = 0.5;
    this.body.fixedRotation = true;
    this.anchor.x = 0.5;
    this.anchor.y = 0;

What the heck is going on here?

Link to comment
Share on other sites

Hey Teonnyn. You get this behavior because the point (X, Y) is on the physics world boundary.

If your body is set to collide with world boundaries (which it is by default), and you create it on the boundary, the collision will force the body out with an impulse.

https://jsfiddle.net/gauravdixitv/q3yjsk9e/ set the variable center to false, and you will see the ball behaving like it does in your code.

 

If you want your ball to come in from outside, make the world bigger :) 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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