benjamin Posted May 31, 2014 Share Posted May 31, 2014 I have a scene where blocks fall from the sky onto the ground. As they do, they stack up thanks to collision separation. I noticed however that after the stack reaches a height of two or three blocks the incoming block somehow forces blocks at the bottom to lose their separation. I want to stop that from happening. If two blocks collide they should remain separated. I am using the arcade physics, (hope that's not the problem). here is the codewindow.onload = function() { 'use strict'; var state = { lastCheckin: 0, pandas: null, preload: function () { game.load.image('panda', 'assets/panda.png'); }, loadUpdate: function () { }, loadRender: function () { }, create: function () { game.physics.startSystem(Phaser.Physics.ARCADE); this.pandas = game.add.group(); }, update: function () { game.physics.arcade.collide(this.pandas, this.pandas); var now = Date.now(), delta = now - this.lastCheckin; if (delta > 1000) { this.lastCheckin = now; var panda = game.add.sprite(Math.random() * game.world.width, 0, 'panda'); this.pandas.add(panda); game.physics.arcade.enable(panda); panda.body.gravity.y = 500; panda.body.collideWorldBounds = true; } }, render: function () { }, paused: function () { }, pauseUpdate: function () { }, shutdown: function () { } } var game = new Phaser.Game(320, 480, null, null, state);}; Link to comment Share on other sites More sharing options...
lewster32 Posted May 31, 2014 Share Posted May 31, 2014 This same topic was covered recently however I can't seem to find the post. I'm pretty sure (correct me if I'm wrong here anyone who knows better) that Arcade physics is not really cut out for this kind of simulation. It has rudimentary separation logic which quickly gets confused by situations involving many collisions and nowhere for the colliding objects to go. Arcade physics is meant to give you a very basic old-school approximation of physical forces, such as gravity, velocity and collisions, such as you'd find in your typical 8 and 16 bit platform games. It's very fast, and can calculate lots of collisions, but is not designed to do the kind of complex operations that people have come to expect from modern games (i.e. Angry Birds style physics). I'd advise you to either work on some way to write some code to 'lock' objects in one or both axes when they are part of a stack, or if you need a more realistic and less arduous approach, use P2 for your physics calculations. Link to comment Share on other sites More sharing options...
benjamin Posted May 31, 2014 Author Share Posted May 31, 2014 I had thought of custom collision handling, but the problem is that by the time arcade calls your collision callback, it's too late, the body may already have overlapped, so if you 'lock' things, it starts to look a little weird. I think you might be right but I'll leave this open until tomorrow incase someone finds a sneaky solution we haven't thought of. Link to comment Share on other sites More sharing options...
lewster32 Posted May 31, 2014 Share Posted May 31, 2014 I think the problem is that Arcade's separation code simply tries to stop two objects intersecting by moving them apart. If you have say three objects all trying to de-intersect from one another, they're gonna start doing weird things and intersecting anyway. The objects never come to rest because they're constantly pushing away from one another. P2 and other advanced physics systems are kitted out to deal with exactly these kinds of situations. Saying that, it would be nice if anyone's found an elegant way to tackle this! Link to comment Share on other sites More sharing options...
benjamin Posted May 31, 2014 Author Share Posted May 31, 2014 I just tried P2, and the results were MUCH better.I'll mark this as answered. thanks lewster! lewster32 1 Link to comment Share on other sites More sharing options...
Recommended Posts