Jump to content

Multiple Collisions


HuskyHarris
 Share

Recommended Posts

Hi

I'm recreating a flash-based game in Phaser, and have run into an issue. I've rendered a 10x10 grid of blocks within a group and you can dig into them from above or from the sides. It mostly works fine, but if you are on top of two blocks at once (see screenshot), only the left-most block's collision is detected. So you can be mostly on top of block b, but if you are even 1px over block a, you will dig down into block a. (In screenshot, pressing the down arrow will dig into the block with red ore in it, whereas it's mostly over the next block along and should dig there instead).

Is there a way to check for multiple collisions, or is there another solution for this issue? I've tried checking to see if the next block has touching.top = true, but it's false.

Cheers

Matt

Screen Shot 2016-10-29 at 19.59.55.png

Link to comment
Share on other sites

Hi Matt, I think what's happening is `arcade.collide` finds the first overlapping block, marks it as touching, and separates the hero and block (by raising the hero slightly). That also separates it vertically from the adjacent block, so the physics engine then marks the adjacent block (correctly) as not touching.

I found I could sort of make it work by running `arcade.overlap` first, then `arcade.collide`, and rewriting the dig prep: https://samme.github.io/Motherload/ (source).

Link to comment
Share on other sites

Hi Samme

Thanks for your help! I made the following change and it's working perfectly now:

if (game.cursors.down.isDown) {
        var left_block = game.ground.getIndex(ground_block);
        var right_block = game.ground.children[left_block + 1];
        // Check if hero is touching multiple blocks
        if (right_block.body.touching.up) {
          // If hero is more over the right-hand block, dig through that instead
          if (hero.body.center.x > right_block.body.position.x) {
            ground_block = right_block;
          }
        }
         digging = true;
         digging_vertical = true;
         game.dig(ground_block, "down");
      }

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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