Jump to content

Collison not working properly for me


Irritating
 Share

Recommended Posts

 

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..

Link to comment
Share on other sites

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

 

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

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

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

 Share

  • Recently Browsing   0 members

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