category filters in physics.raycast()

The physics.raycast function documentation refers to additional parameters that can be used as “category filters”.
Are there any examples of how these are used?

You can set the filter categories and mask for a body to filter collisions. You can also use these categories with raycasts to filter what objects will be detected:

player = physics.body(CIRCLE, 50)
player.categories = {1}
enemy = physics.body(CIRCLE, 25)
enemy.categories = {2}

-- the additional parameter is the category to test against (there can be more than one)
-- which will limit the raycast to detecting enemy (which is in category 2)
hit = physics.raycast(point1, point2, 2)
print("hit " .. hit.body)

That’s great, I’ll give that a try. Where did you get this information from, is it from the box2d documentation?

There’s some stuff about filtering in the physics lab example project and documentation. I also wrote the physics API for Codea. I’ll look into improving the physics docs in future.

Wow, great work John. I was just going over the main physics example last night, fun and powerful.

Only drawback with the examples is the lack of comments. Then again it really forces you to hard examine all the code to see how it all ticks.

Yes, great work with the physics api!