Sign in to follow this  

P2-When the player touches a wal over the side it gets stuck

Recommended Posts

Hi! For several months, I have this problem and have not been able to fix it. 

I made a post about it while communicating my problem. 



I use physical P2. When the player touches a wall or jump over the side it gets stuck and does not fall as it should.


Some of my code:

// map ='level1_1');'sand');,;

this.layer ='Sand');
// this.layer.debug = true;
this.layer_tiles =, this.layer);

// materials & collision groups
this.playerMaterial ='player');
this.layerMaterial ='layer');
this.enemyMaterial ='enemy');
this.playerCG =;
this.enemyCG =;
this.layerCG =;

function setupLayer(layer_tiles, theGame) {
var layerLength = layer_tiles.length;
for (var i = 0; i < layerLength; i++) {
layer_tiles[i].collides([theGame.playerCG, theGame.enemyCG]);

setupLayer(this.layer_tiles, this);

// player;

player.scale.setTo(0.5, 0.5);
player.body.fixedRotation = true;
player.anchor.setTo(0.5, 0.5);
player.body.collideWorldBounds = true;

player.body.collides([this.layerCG, this.enemyCG]);

player.body.createGroupCallback(this.enemyCG, collisions.collisionEnemy, this);
player.body.mass = 50;


Can anybody help me? 

A greeting.

Share this post

Link to post
Share on other sites

I would put something like that in the collision callback:





It's a hack, don't know if it would work 100% all the time, or if it would work at all, depends on the value of velocity.x at the moment of the collision, I don't use P2, but that might do the trick.


Also, some condition might be required to evaluate if the player is facing the wall or not.


But it's a hack, it's not the real deal.

Share this post

Link to post
Share on other sites

Tilemaps may not be ideal for p2 physics. You could try polygonal collision shapes. I think the problem is that the collision thinks the player is colliding with the top of the tile (since it overlaps the corner, there are two intersection points, one on the side and one on top, and as far as I know, p2 doesn't check for further intersection points after it has found one, I could be wrong about this though).

Share this post

Link to post
Share on other sites

I tried the hack and not solve the problem :(


On the other hand whatwayfinder says is what happens. Rich Mentions in this post: 


All levels of my game are mounted with tilemap ... there any example to fix the bug. Even in the Phaser example exits the problem:



Share this post

Link to post
Share on other sites

just in case i didn't already write how i managed this problem:


i got rid of colliding tilemaps entirely..  i still "paint" the world in the tilemap layer but in my code i never activate collisions on this layer..  instead i also create an object layer and paint the collision areas with "polylines"


that way there is no gap between the tiles anymore..  (similar to what wayfinder wrote above)


to go further i implemented a check if my player is on air (not touching any ground) and the moment he is on air i change his material to "ice" with zero friction.. that way the problem is solved.


to avoid this "onAir" check i could also work with 2 object layers and paint all the platform-polylines on one layer and all the wall-polylines on the other and give the "wall-layer" the ice material...

Share this post

Link to post
Share on other sites


you can try it here and browse through the code if you want..   

i also made an example on how to add polylines here:  (is that case its a mixture between collideable tiles and polylines..  now i do only polylines and no tiles anymore..

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.