Collision Filter Inquiry

Two parter:

 1)

The pinned post in this area says that you should place all your collision filters for all your objects near the top of your main file and later when you add physics bodies to your objects put in the appropriate filter.

Does it have to be at the top of your main? 

I’ve seperated my object creation/manipulation for each object into its own file, easier way for me to manage objects.

Where would I put all the filters?

 2)

I am trying to make it so that only the player can collide with any obstacle, so no obstacle or collectible, or anything can can collide with each other, only the player. 

So are these filters correct?

[lua]

local playerCollisionFilter = { categoryBits = 1, maskBits = 6 }

local obstacleCollisionFilter = { categoryBits = 2, maskBits = 1 }

local collectiblesCollisionFilter = { categoryBits = 4, maskBits = 1 }

[/lua]

For the life of me I can’t get the obstacles and collectibles to NOT collide with each other. This is my code for creating, lets say, one of my obstacles

[lua]

 obstacle = createJet(y)

physics.addBody(obstacle, {filter = obstacleCollisionFilter})

[/lua]

Hi @rgame,

If you worked through the collision filters “Helper Chart” (which I assume you referenced), and you did the process correctly, the filters should work.

The actual references to your filters don’t necessarily need to be at the “top” of your file. Simply, they need to be known (scoped) properly to whatever physics addBody calls are using them. If the call can’t recognize the filter table for whatever reason (scoping issue), that may explain why you’re still getting collisions between everything.

Hope this helps,

Brent Sorrentino

Thanks Brent, I figured out what my issue with it was ( I wasn’t applying the filter to all my obstacles ) but the scope answer did help me clear things up a bit. Thanks

Hi @rgame,

If you worked through the collision filters “Helper Chart” (which I assume you referenced), and you did the process correctly, the filters should work.

The actual references to your filters don’t necessarily need to be at the “top” of your file. Simply, they need to be known (scoped) properly to whatever physics addBody calls are using them. If the call can’t recognize the filter table for whatever reason (scoping issue), that may explain why you’re still getting collisions between everything.

Hope this helps,

Brent Sorrentino

Thanks Brent, I figured out what my issue with it was ( I wasn’t applying the filter to all my obstacles ) but the scope answer did help me clear things up a bit. Thanks