Jump to content

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


AlexArroyoDuque
 Share

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
this.map = this.game.add.tilemap('level1_1');
this.map.addTilesetImage('sand');
this.map.setCollisionBetween(0, this.map.tiles.length);

this.layer = this.map.createLayer('Sand');
// this.layer.debug = true;
this.layer.resizeWorld();
this.layer_tiles = this.game.physics.p2.convertTilemap(this.map, this.layer);


// materials & collision groups
this.playerMaterial = this.game.physics.p2.createMaterial('player');
this.layerMaterial = this.game.physics.p2.createMaterial('layer');
this.enemyMaterial = this.game.physics.p2.createMaterial('enemy');
this.playerCG = this.game.physics.p2.createCollisionGroup();
this.enemyCG = this.game.physics.p2.createCollisionGroup();
this.layerCG = this.game.physics.p2.createCollisionGroup();




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

setupLayer(this.layer_tiles, this);


// player
this.game.physics.p2.enable(player);

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

player.body.setCircle(15);
player.body.setCollisionGroup(this.playerCG);
player.body.setMaterial(this.playerMaterial);
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.

Link to comment
Share on other sites

I would put something like that in the collision callback:

 

sprite.body.velocity.x*=-1;

 

 

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.

Link to comment
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).

Link to comment
Share on other sites

Hi! 

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:


 

Greetings!

Link to comment
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...

Link to comment
Share on other sites

http://test.xapient.net/phaser/attm/

 

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

 

http://www.html5gamedevs.com/topic/6556-how-to-export-from-tiled-and-integrate-into-phaser/?p=39495

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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