Allow bodies to overlap while detecting contacts with sensors

Sometimes in your games, you may need two bodies to overlap just like there wasn't any collision, while detecting the collision. This can be achieved using a sensor: a fixture that detects contacts without producing responses.

You can use sensors to create bodies so that you'll know when they collide without any physical contact between them. Just think about a character controlled by the player and a switch: you want to know when the player hits the switch to trigger some event, but at the same time you don't want the switch to react to player collision.

In this last script we'll test a sensor.

  1. First, add the Contacts class to the package. This is not required to create a sensor, it's ...

Get Box2D for Flash Games now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.