Jump to content

Phaser P2 Physics going weird?


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:


  Here is the code for P2:

    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');
    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


  • Recently Browsing   0 members

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