Jump to content

P2: Sensors: How do they work?


codevinsky
 Share

Recommended Posts

I'm trying to add a second shape to a body that is a sensor only.

 

The first shape in the body is triggering collisions correctly, but the the sensor shape is not.

 

Here's the code:

var cop = policeGroup.getFirstExists(false);      if(!cop) {        cop = game.add.sprite(game.width,500,'police');        game.physics.p2.enable(cop,true);        cop.body.clearShapes();        cop.body.loadPolygon('physicsData', 'police-car');        cop.body.fixedRotation = true;        cop.body.data.motionState = p2.Body.KINEMATIC;        cop.body.bounce = 0;        cop.body.name = 'enemy';        var circle = cop.body.addCircle(40,0,120);        circle.sensor = true;        cop.body.setCollisionGroup(enemyCollisionGroup);        cop.body.collides(playerCollisionGroup);                cop.outOfBoundKill = true;        cop.checkWorldBounds = true;        debugger;      }      cop.reset(game.width, 500);      cop.revive();      cop.body.moveLeft(300);      copTimer = game.time.now + 2000;

The polygon is colliding correctly, however, the circle isn't.

 

What am I doing wrong?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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