schteppe / p2.js

JavaScript 2D physics library
Other
2.64k stars 330 forks source link

Bodies collides but overlapping each other? #261

Closed deniztraka closed 7 years ago

deniztraka commented 7 years ago

Hi, I have problem with the bodies. They are overlapping each other.

This is my body creating code.

p2.Body.call(this, {
        mass: constants.game.player.mass,
        position: [utils.math.randomInt(0, config.game.bounds.width), utils.math.randomInt(0, config.game.bounds.height)],
        type: p2.Body.DYNAMIC
    });
    this.damping = 1;

    var playerShape = new p2.Circle({ radius: constants.game.player.radius });
    playerShape.collisionGroup = Math.pow(2, 0);
    playerShape.collisionMask = Math.pow(2, 0);
    this.addShape(playerShape);

i'm adding this objects to world. world.on('beginContact', onBeginContact); is fired when they are colliding each other. But at the same time they are overlapping each other...

Also this is my world initializing code for info.

var world = new p2.World({
    gravity: [0, 0],
    islandSplit: true
});
world.solver = new p2.GSSolver();
world.solver.iterations = 25;
world.solver.tolerance = 0.01;

Everything is same with the tutorials, i do not know where can i look and how can fix this issue.. Can you please help me with this problem? For more info, the repository of those codes in here if you like to examine it.. https://github.com/deniztraka/MultiplayerMessup

Best regards and thank you for this physics library :) deniz

schteppe commented 7 years ago

Hi, I'm not fully understanding the question. What is the problem? Contact event not firing properly? Too much overlap? There will always be a small overlap in a collision.

schteppe commented 7 years ago

Also why do you set damping = 1?

deniztraka commented 7 years ago

i set damping to 1 because , i only need collision for bodies for now. i dont want any force to them. the problem occurs when i inherit the body class. maybe i did it wrong in the player.js player.js url because it works well without inheritance.