AlexArroyoDuque Posted August 30, 2014 Share Posted August 30, 2014 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. http://www.html5gamedevs.com/topic/4807-physics-bodies-stick-when-colliding-from-the-side/#entry32859 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 More sharing options...
AlexArroyoDuque Posted August 30, 2014 Author Share Posted August 30, 2014 Link to comment Share on other sites More sharing options...
JUL Posted August 30, 2014 Share Posted August 30, 2014 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 More sharing options...
wayfinder Posted August 30, 2014 Share Posted August 30, 2014 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 More sharing options...
AlexArroyoDuque Posted August 31, 2014 Author Share Posted August 31, 2014 Hi! I tried the hack and not solve the problem On the other hand whatwayfinder says is what happens. Rich Mentions in this post: http://www.html5gamedevs.com/topic/4807-physics-bodies-stick-when-colliding-from-the-side/#entry32859 All levels of my game are mounted with tilemap ... there any example to fix the bug. Even in the Phaser example exits the problem:http://examples.phaser.io/_site/view_full.html?d=p2%20physics&f=tilemap+gravity.js&t=tilemap%20gravity Greetings! Link to comment Share on other sites More sharing options...
JUL Posted August 31, 2014 Share Posted August 31, 2014 If you're using sprite.scale.x, at the moment of collision, try sprite.body.velocity.x= -sprite.scale.x*100;Again it's hack Link to comment Share on other sites More sharing options...
AlexArroyoDuque Posted September 1, 2014 Author Share Posted September 1, 2014 @JUL, I think the hack does not work because I did not check if touching wall.You know how I know if the player is touching a wall? Regards Link to comment Share on other sites More sharing options...
valueerror Posted September 2, 2014 Share Posted September 2, 2014 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 More sharing options...
AlexArroyoDuque Posted September 3, 2014 Author Share Posted September 3, 2014 Thanks @valueerror. You have an example to apply what you comment? I do not understand exactly how to implement it. Regards. Link to comment Share on other sites More sharing options...
valueerror Posted September 3, 2014 Share Posted September 3, 2014 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 AlexArroyoDuque 1 Link to comment Share on other sites More sharing options...
AlexArroyoDuque Posted September 9, 2014 Author Share Posted September 9, 2014 Thanks @valueerror When I have some time I will adapt my maps and try your method. Link to comment Share on other sites More sharing options...
Recommended Posts