Teonnyn Posted January 15, 2018 Share Posted January 15, 2018 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 More sharing options...
gauravD Posted January 15, 2018 Share Posted January 15, 2018 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 in mono 1 Link to comment Share on other sites More sharing options...
Teonnyn Posted January 15, 2018 Author Share Posted January 15, 2018 DOH! I'm going to file this one in "obvious in hindsight", but it was late-night last night when I posted and there were hours of frustration building on that. Thank you! Link to comment Share on other sites More sharing options...
Recommended Posts