HuskyHarris Posted October 29, 2016 Share Posted October 29, 2016 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 Link to comment Share on other sites More sharing options...
samme Posted October 29, 2016 Share Posted October 29, 2016 That's odd, if you're testing the whole group it should be giving you all the collisions. Do you have a live example? Link to comment Share on other sites More sharing options...
HuskyHarris Posted October 30, 2016 Author Share Posted October 30, 2016 Hi Samme, thanks for replying. Game: http://matthewharris.org.uk/games/Motherload/ Source: https://github.com/MattHarris91/Motherload Cheers Matt Link to comment Share on other sites More sharing options...
samme Posted October 31, 2016 Share Posted October 31, 2016 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 More sharing options...
HuskyHarris Posted October 31, 2016 Author Share Posted October 31, 2016 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 More sharing options...
Recommended Posts