Jump to content

Created Objects Collision Issue


CarrotIsland
 Share

Recommended Posts

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 Code

In 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

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...