CarrotIsland Posted March 31, 2014 Share Posted March 31, 2014 Hey all, I have been working on a side-scroller game in Phaser on and off for a week or so now and seem to have hit a wall. Basis of the game: You play a guy that shoots blocks and then uses said blocks to traverse a level. Problem: I am able to shoot blocks and finally able to jump off of blocks because I made them immovable. However, this removes their collision and thus all other blocks just go straight through them. This is a problem because I need blocks to stack and collide and such. Block CodeIn create():blocks = game.add.group();blocks.enableBody = true;blocks.physicsBodyType = Phaser.Physics.ARCADE; In update():game.physics.arcade.collide(player, layer);game.physics.arcade.collide(player, blocks);game.physics.arcade.collide(blocks, layer);game.physics.arcade.collide(blocks, blocks);// movement codeif (shootButton.isDown) { fire();}function fire () { if (game.time.now > shootTimer) { shootTimer = game.time.now + fireRate; block = blocks.create(player.x + 50, player.y, 'block'); block.body.immovable = true; block.body.collideWorldBounds = true; block.body.velocity.x = 400; } }All code:Gist- CarrotIsland Link to comment Share on other sites More sharing options...
rich Posted April 1, 2014 Share Posted April 1, 2014 An 'immovable' body will still collide with other bodies, just not other immovable ones. In your case is there a reason you need to make them immovable when you create them? Would just giving them a high mass value suffice? Link to comment Share on other sites More sharing options...
CarrotIsland Posted April 1, 2014 Author Share Posted April 1, 2014 Hey Rich,My problem is that without the immovable property my player cannot jump off the blocks.I jump on top a block then jump ceases to function. - CarrotIsland Link to comment Share on other sites More sharing options...
rich Posted April 1, 2014 Share Posted April 1, 2014 How are you checking to see if your player can jump? Link to comment Share on other sites More sharing options...
CarrotIsland Posted April 1, 2014 Author Share Posted April 1, 2014 if ((cursors.up.isDown || spacebar.isDown || wKey.isDown) && (player.body.onFloor() || player.body.touching.down) && game.time.now > jumpTimer) { player.body.velocity.y = -175; jumpTimer = game.time.now + 750; }Like so.All of the code can be found here. Link to comment Share on other sites More sharing options...
TomFiveThumbs Posted April 3, 2014 Share Posted April 3, 2014 Looks like you started with the same tutorial I did. I had problems with the touching.down as well. It was fine when the guy was on the ground, but other than that he wouldn't jump. What I did instead was, on jumping, made a boolean jumped = true; and on update function I put var p2 = game.physics.arcade.collide(player, boxes);var p1 = game.physics.arcade.collide(player, platforms);if((p1 || p2) && jumped)jumped = false;Just as a confirmation that he's hit the boxes at some point in his jump. so I check (player.body.onFloor || player.body.touching.down || !jumped) One problem is, if your guy hits a box side-on mid jump, he'll essentially be able to wall jump as much as he wants. It's early days for me too, but that seems to be the right step forward for what I wanted. Link to comment Share on other sites More sharing options...
CarrotIsland Posted April 3, 2014 Author Share Posted April 3, 2014 Okay, sweet TomFiveThumbs!If I replace my use of immovable with this, my block collision should be solved. I'll check back here after I try it. - CarrotIsland Link to comment Share on other sites More sharing options...
CarrotIsland Posted April 4, 2014 Author Share Posted April 4, 2014 Okay! I replaced some of my code with your solution. It does fix my initial problem: can't jump off blocks Next problem: blocks collapse onto each other with enough force. I want force to no act on these.Turn off physics? (maybe?)- CarrotIsland Link to comment Share on other sites More sharing options...
Recommended Posts