BigRob154 Posted April 15, 2014 Share Posted April 15, 2014 Hi I'm working on a prototype and have some problems with P2. I've some bubbles in the scene which grow over time. When changing the body's radius in the update function the whole scene gets out of control and the bubbles go crazy, jumping around everywhere. create: function() { this.game.physics.startSystem(Phaser.Physics.P2JS); for (var i = 0; i < 10; i++) { var x = (Math.random() * this.game.width) | 0, y = (Math.random() * this.game.height) | 0, d = 30; var s = this.game.add.sprite(x, y, ''); s.anchor.set(0.5, 0.5); this.game.physics.p2.enable(s); var p2Shape = s.body.addCircle(d, 0, 0, 0); s.body.debug = true; this.objects.push({ sprite: s, physicShape: p2Shape }); } }, update: function() { for (var i = 0; i < this.objects.length; i++) { var o = this.objects[i]; // same result //o.sprite.body.setCircle(o.physicShape.radius + 0.1, 0, 0, 0); o.physicShape.radius += 0.1; o.physicShape.boundingRadius = o.physicShape.radius; } }Am I doing something terribly wrong here? Link to comment Share on other sites More sharing options...
JP91 Posted April 15, 2014 Share Posted April 15, 2014 try to take the "for" out of the update. Link to comment Share on other sites More sharing options...
BigRob154 Posted April 16, 2014 Author Share Posted April 16, 2014 try to take the "for" out of the update. Why should I do that? I'm updating a bunch of objects in this for loop. Link to comment Share on other sites More sharing options...
schteppe Posted April 16, 2014 Share Posted April 16, 2014 I think you might be updating the physics shape too fast. They grow to something that cover the whole physics world, and the contact solver goes bananas. Try setting o.physicShape.radius += 0.005;instead, and you might have a chance to see what's happening. Note that the physics debug rendering of the sprite does not get updated automatically. I tried to doo.sprite.body.debugBody.draw();and it works but that will also randomize the color on the debug rendering each frame... Disco! Link to comment Share on other sites More sharing options...
BigRob154 Posted April 16, 2014 Author Share Posted April 16, 2014 Yep, it's not bouncing around like crazy anymore. Didn't know that I've to call debugBody.draw() manually, thanks for the hint.But there is another problem, now. The whole simulation gets unstable. Bubbles are overlapping each other und shoot out like crazy. Looks like the collision isn't always triggered. o.physicShape.radius += 0.005; o.physicShape.updateBoundingRadius(); o.sprite.body.debugBody.draw(); Link to comment Share on other sites More sharing options...
schteppe Posted April 17, 2014 Share Posted April 17, 2014 Okay... Do they overlap at the end of the simulation, or when the bubbles have grows to cover the screen, or in the beginning, or all the time? I run the latest Phaser and I'm not sure I get the same result. Link to comment Share on other sites More sharing options...
BigRob154 Posted April 17, 2014 Author Share Posted April 17, 2014 Thanks for your help @schteppe. Updated from Phaser 2.0.2 to 2.0.3 and it's working now. Link to comment Share on other sites More sharing options...
Recommended Posts