Sign in to follow this  
Teonnyn

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:

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?

Share this post


Link to post
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 :) 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.