colgate Posted July 29, 2014 Share Posted July 29, 2014 Hi, New to Phaser, but I can't seem to get some basic functionality working. Using Arcade physics, when my sprites hop on top of each other they compress and sometimes fall through the floor. Like so: I've feel like I've tried everything but I wouldn't be surprised if I missed something obvious. Here's what I hope is the relevant code. Please forgive its poor quality. I've also attached the whole file if that helps. Thanks!function create() { // A simple background for our game game.add.sprite(0, 0, 'sky'); // The platforms group contains the ground and the 2 ledges we can jump on platforms = game.add.group(); // We will enable physics for any object that is created in this group platforms.enableBody = true; // Here we create the ground. var ground = platforms.create(0, game.world.height-64, 'ground'); // Scale it to fit the width of the game (the original sprite is 400x32 in size) ground.scale.setTo(2, 2); // This stops it from falling away when you jump on it ground.body.immovable = true; ground.body.allowGravity = false; // The player and its settings player = game.add.sprite(150, game.world.height - 150, 'dude'); player2 = game.add.sprite(300, game.world.height - 150, 'dude'); player3 = game.add.sprite(450, game.world.height - 150, 'dude'); player4 = game.add.sprite(600, game.world.height - 150, 'dude'); players = game.add.group(); players.add(player); players.add(player2); players.add(player3); players.add(player4); // We need to enable physics on the player game.physics.arcade.enable(players, Phaser.Physics.ARCADE); game.physics.arcade.OVERLAP_BIAS = 30; game.physics.arcade.TILE_BIAS = 1000; game.physics.arcade.gravity.y = 2600; players.callAll('body.collideWorldBounds', 'body', true); player.body.bounce.x = 0; player.body.bounce.y = 0; player.body.allowRotation = false; player2.body.bounce.x =0; player2.body.bounce.y =0; player2.body.allowRotation = false; player3.body.bounce.x =0; player3.body.bounce.y =0; player3.body.allowRotation = false; player4.body.bounce.x =0; player4.body.bounce.y =0; player4.body.allowRotation = false; // Our two animations, walking left and right. players.callAll('animations.add', 'animations', 'left', [0, 1, 2, 3], 10, true); players.callAll('animations.add', 'animations', 'right', [5, 6, 7, 8], 10, true); // The score scoreText = game.add.text(200, 300, '', { fontSize: '68px', fill: '#000' }); // Our controls. cursors = game.input.keyboard.createCursorKeys(); // Finally some stars to collect stars = game.add.group(); // We will enable physics for any star that is created in this group stars.enableBody = true;}function update() { // Collide the player and the stars with the platforms game.physics.arcade.collide(platforms, players); game.physics.arcade.collide(players, players); game.physics.arcade.collide(stars, platforms); // Checks to see if the player overlaps with any of the stars, if he does call the collectStar function game.physics.arcade.overlap(players, stars, collectStar, null, this); // Reset the players velocity (movement) player.body.velocity.x = 0; player2.body.velocity.x = 0; player3.body.velocity.x = 0; player4.body.velocity.x = 0; player.body.angle = 0; player2.body.angle = 0; player3.body.angle = 0; player4.body.angle = 0; }index.html Link to comment Share on other sites More sharing options...
colgate Posted July 30, 2014 Author Share Posted July 30, 2014 Has anyone else encountered this before? Link to comment Share on other sites More sharing options...
lewster32 Posted July 30, 2014 Share Posted July 30, 2014 Yes, this is a shortcoming in the separation code of Arcade Physics, which was not designed for this kind of multi-body contact. The more things are stacked on top of one another, the more weird it gets. See this post for possible workarounds: http://www.html5gamedevs.com/topic/7810-how-to-increase-rigidity-of-arcade-sprite-bodies/ colgate 1 Link to comment Share on other sites More sharing options...
colgate Posted July 30, 2014 Author Share Posted July 30, 2014 Thanks for the clarification; makes me feel a bit better. Link to comment Share on other sites More sharing options...
Recommended Posts