Jump to content

Weird collision with p2 physics


onedkr
 Share

Recommended Posts

Hi everyone,

 

I have one problem, I'm a beginner with Phaser and I just passed my game with p2 physics.

I have three sprite : the floor and 2 different player. Each player have to collide together and with the floor of course.

 

The two players collide correctly with the ground. However when the player 1 collides with the player 2 (or inverse) and I continue to move the player to the other player's direction, the first one pushes the second player. When I stop the first player is push backward.
 
I just want that the first player cannot move if he touch the second player (like a wall). How is it possible ? I tried to reset all the force and velocity parameters, but that doesn't works...

 

initialize group collision :

playerCollisionGroup = game.physics.p2.createCollisionGroup();enemyCollisionGroup = game.physics.p2.createCollisionGroup();groundCollisionGroup = game.physics.p2.createCollisionGroup();game.physics.p2.updateBoundsCollisionGroup();

Here my code for the ground :

ground = game.add.sprite(game.world.centerX, GAME_HEIGHT - 55, 'ground');ground.scale.setTo(40, 1);game.physics.p2.enable(ground, true);ground.body.static = true;ground.body.setCollisionGroup(groundCollisionGroup);ground.body.collides([playerCollisionGroup, enemyCollisionGroup]);

For each player I initialize like this : 

function initBody(carac) {	if(carac.name == "player")		body = carac.create(game.world.centerX - 300, GAME_HEIGHT - 255 - (GAME_HEIGHT - ground.body.y), 'body');	else if(carac.name == "enemy") {		body = carac.create(game.world.centerX + 320, GAME_HEIGHT - 250 - (GAME_HEIGHT - ground.body.y), 'body');		body.scale.x = -1;	}	body.body.setZeroForce();	body.body.setZeroVelocity();	body.body.setZeroDamping();	body.body.angularForce = 0;	body.body.angularVelocity = 0;	body.body.angularDamping = 0;    body.body.fixedRotation = true;	body.animations.add('normal', [0,1]);	body.animations.add('jump', [0]);	body.animations.add('move', [2]);	//  Set the body collision group	if(carac.name == "player") {		body.body.setCollisionGroup(playerCollisionGroup);		body.body.collides([groundCollisionGroup, enemyCollisionGroup]);	}	else if(carac.name == "enemy") {		body.body.setCollisionGroup(enemyCollisionGroup);		body.body.collides([groundCollisionGroup, playerCollisionGroup]);	}	return body;}
 
Any idea ?
Thank you very much for your answers :)
Link to comment
Share on other sites

I just noticed that more the player is faster (px per second) more the force which push the player 2 and after push backward the player 1 is stronger.

I don't find a solution in the doc to delete these "forces" ... :/

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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