ckskylight Posted January 8, 2014 Share Posted January 8, 2014 Hi All! I'm new to Phaser and I've been trying to figure out how the physics engine works by modifying the tutorial code. In the game I want to make, I want the user to be able to build walls by stacking blocks on top of one another, and I want the walls to be demolished by projectiles, so I need to use the physics engine. However, I discovered that stacking too many blocks makes the blocks fall through the ground because they are "too heavy". Is there a way to get rid of this problem? Below are two screenshots: the first one is as the blocks start to fall through and the second is after they've fallen through and are stable again. Link to comment Share on other sites More sharing options...
BitlasLT Posted January 8, 2014 Share Posted January 8, 2014 Hi , is it possible to get code? Link to comment Share on other sites More sharing options...
ckskylight Posted January 8, 2014 Author Share Posted January 8, 2014 Here is the relevant code:var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });function preload() { game.load.image('sky', 'assets/sky.png'); game.load.image('ground', 'assets/platform.png'); game.load.image('star', 'assets/star.png'); game.load.spritesheet('dude', 'assets/dude.png', 32, 48); game.load.image('diamond', 'assets/diamond.png'); game.load.image('block', 'assets/firstaid.png');}var platforms;var cursors; var blocks;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(); // 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; // Now let's create two ledges var ledge = platforms.create(400, 400, 'ground'); ledge.body.immovable = true; ledge = platforms.create(-150, 250, 'ground'); ledge.body.immovable = true; // Our controls. cursors = game.input.keyboard.createCursorKeys(); blocks = game.add.group(); game.input.onDown.add(createBlock, this); }function update() { game.physics.collide(blocks, platforms); game.physics.collide(blocks, blocks);} function createBlock() { var block = blocks.create(game.input.mousePointer.x, game.input.mousePointer.y, 'block'); block.body.acceleration.y = 100; block.body.allowRotation = true; block.body.mass = 3; block.body.bounce.y = 0;} Link to comment Share on other sites More sharing options...
nOnAmE Posted May 24, 2014 Share Posted May 24, 2014 I got the same error, could someone explain why this happens?I use Phaser 2.0.5 Link to comment Share on other sites More sharing options...
j0hnskot Posted May 24, 2014 Share Posted May 24, 2014 I don't think it will change something but worths the shot. Can you change the 'game.physics.arcade.collide(blocks, blocks)'to 'game.physics.arcade,collide(blocks)' and see what happens? ComputDroid 1 Link to comment Share on other sites More sharing options...
j0hnskot Posted May 24, 2014 Share Posted May 24, 2014 if you reduce mass to 0 they won't go through the floor but still they will move a little bit into it. I'm trying to figure out a better solution. Edit: The problem is (probably) that two collisions happen on the same time.Sadly my knowledge stops here, i can't help you further . Link to comment Share on other sites More sharing options...
nOnAmE Posted May 24, 2014 Share Posted May 24, 2014 thank you for your try.i can't fix this problem Link to comment Share on other sites More sharing options...
Recommended Posts