schteppe / p2.js

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

CCD doesn't work with collisionGroups ? #359

Open ramirofages opened 3 years ago

ramirofages commented 3 years ago

Hello, I found this weird issue with the following configuration:

I have a few balls bouncing around in a contained square (the container is made up of 4 planes) like so:

// BALL BODY CREATION
let collision_groups = {
      BALL: Math.pow(2,0),
      WALL: Math.pow(2,1)
}
let ball_body = new p2.Body({
        mass: 1,
        ccdSpeedThreshold: 0,
        damping: 0,
        angularDamping: 0,
        type : p2.Body.DYNAMIC,
        allowSleep: false
      });

ball_body.addShape(new p2.Circle({ 
        radius: 0.5, 
        collisionGroup: collision_groups.BALL,
        collisionMask: collision_groups.WALL 
      }));
//#################
//#################
// WALL BODY CREATION
let wall_body = new p2.Body({
      mass: 0, 
      position: [x,y],
      angle: THREE.Math.degToRad(rotation) // I use this and the position to put the planes in a square-like shape
    });

wall_body .addShape(new p2.Plane({
      collisionGroup: collision_groups.WALL,
      collisionMask: collision_groups.BALL
      }));

//####################
//####################
// WORLD CREATION
    let world = new p2.World({
        gravity:[0, 0],
        applyDamping : false,
        applyGravity: false
    });
    world.setGlobalStiffness(1e18)
    world.defaultContactMaterial.frictionStiffness = 1e18;
    world.defaultContactMaterial.restitution = 1;
    world.defaultContactMaterial.friction = 0;

I then fire a few balls that go very fast, and when the balls intersect each other, they get stuck between said balls. And the weird thing is that I set my collision masks explicitly to avoid having balls colliding with each other :/ They bounce around fine against the walls, so no problems there. Then if I remove the line 'ccdSpeedThreshold: 0' to disable CCD, they work fine, and the balls don't get stuck anymore when they collide with each other. Am I missing something? I would upload a test case but unfortunately I have this integrated with a complex system running threejs for the visualization... but here is a screenshot with the balls stuck: imagen

visarunas commented 3 years ago

I think this is related to #347 , I am experiencing something similar. Did you find a fix?