Irritating Posted October 16, 2017 Share Posted October 16, 2017 I am trying to make a simple game with this super cool engine. But I am facing some issues regarding the collisions i have setup. Can anyone please help me on this. Code Link:: https://github.com/Vikas00kr/Dodge Link to comment Share on other sites More sharing options...
samid737 Posted October 16, 2017 Share Posted October 16, 2017 What exactly is the problem? Link to comment Share on other sites More sharing options...
Irritating Posted October 16, 2017 Author Share Posted October 16, 2017 The boxes i created in a group are not colliding with each other. They should be stacked on top of each other but some of them go through. Link to comment Share on other sites More sharing options...
samid737 Posted October 17, 2017 Share Posted October 17, 2017 I believe this is due to tunneling, where the object is moving too fast for the collision to be noticed by the physics system. Decreasing gravity might solve everything in your case, since each enemy will have a lower speed at collision when blocks are being piled up (the first few enemy blocks are causing problems). An alternative is to try to reshape your blocks once they collide via A callBack using setSize(). If you make them large enough in y direction , they should not pass trough anymore. Might have some errors but the idea is: game.physics.arcade.collide(player, ground); game.physics.arcade.collide(enemy,enemy,rescale); game.physics.arcade.collide(enemy, ground,rescale); game.physics.arcade.collide(player, enemy); //rescale the enemy when colliding function rescale(enemy1,enemy2){ if(enemy2.body.moves){//if we not already rescaled enemy2.body.moves=false;//stop moving enemy2.body.setSize(enemy2.width,400,0,0);//reset physics body shape, increase the height enemy2.y+=(enemy1.y-enemy2.y-enemy2.height);//move a bit downwards, delete to see difference } } Try it see if it works for your game.. Irritating 1 Link to comment Share on other sites More sharing options...
Irritating Posted October 17, 2017 Author Share Posted October 17, 2017 Many thanks samid737 for looking into and explaining to me about Tunneling, i checked and if i put gravity more than 169 then only collision is not working. I also tried your code for resizing the blocks via callback it is working fine, i just need to tweek some thing here and there. Also I am using Phaser v2.8.0, so by any chance Tunneling is happening because of old version and in the newer versions this works fine. Link to comment Share on other sites More sharing options...
samid737 Posted October 17, 2017 Share Posted October 17, 2017 It could be im not sure if v2.9.1 solves this. Also note that the body will remain rectangular when rescaling, so if you try to move the player it could get stuck in between blocks. I just tested the game without using setSize() and it works Try deleting that line specifically:, it should work without adjusting the body shape: function rescale(enemy1,enemy2){ //should rename it to something like stopBlock if(enemy2.body.moves){ enemy2.body.moves=false; enemy2.y+=(enemy1.y-enemy2.y-enemy2.height); } } I think there was some property or method that deals with this, but I can't recall which one. Link to comment Share on other sites More sharing options...
Irritating Posted October 17, 2017 Author Share Posted October 17, 2017 yes... working perfectly . But i am noticing one more thing now that when i place my player body on top of the boxes then the colliding body shape of boxes is being shifted down, like they are pushed down because of the weight of player. Is this also because of Tunneling or i messed up/missed something in code. Link to comment Share on other sites More sharing options...
samid737 Posted October 17, 2017 Share Posted October 17, 2017 No, you can set immovable to true inside the callBack function to avoid this. Link to comment Share on other sites More sharing options...
Irritating Posted October 17, 2017 Author Share Posted October 17, 2017 oooh....Yes. Thank you very much. samid737 1 Link to comment Share on other sites More sharing options...
Irritating Posted October 17, 2017 Author Share Posted October 17, 2017 Hey samid737, Sorry to disturb u again, I tried immovable=true but its not working(i set to both just to be sure). function rescale(enemy1,enemy2){ if(enemy2.body.moves){//if we not already rescaled enemy2.body.moves=false;//stop moving enemy1.immovable=true; enemy2.immovable=true; enemy2.y+=(enemy1.y-enemy2.y-enemy2.height);//move a bit downwards, delete to see difference } } Link to comment Share on other sites More sharing options...
samid737 Posted October 17, 2017 Share Posted October 17, 2017 Try: enemy2.body.immovable = true; Irritating 1 Link to comment Share on other sites More sharing options...
Irritating Posted October 17, 2017 Author Share Posted October 17, 2017 Yes this works perfectly. samid737 1 Link to comment Share on other sites More sharing options...
Recommended Posts