Help with Collision masking

I am having problems understanding how to use collision filter and masking

I want my flyships to collide with the walls but not with eachother.

I set two catergory filter

flyShipCollisionFilter = { categoryBits = 2}
wallCollisionFilter = {categoryBits = 1}

flyshipbody should have which filter?
wallbody should have which filter?
Thanks [import]uid: 8192 topic_id: 1811 reply_id: 301811[/import]

Anyone on this?

I am having problems understanding the masking number and what it signifies. It makes no sense.
Thanks [import]uid: 8192 topic_id: 1811 reply_id: 5441[/import]

Used the following when creating my objects, which according to instruction should not let the 4 instances of my object collide with eachother but collide with everything else. They still collide with everything.

Could someone please give me a hand. I am really stuck and can’t go forward with my game. Thanks in advance.

[code]
shipCollisionFilter = { groupIndex = -1 }

[code] [import]uid: 8192 topic_id: 1811 reply_id: 5448[/import]

Went on the Box2d site here is the solution. It was confusing with the bits numbers but it’s actually very straightforward

[code]
local wallCollisionFilter = { categoryBits = 1, maskBits = 1}
local shipCollisionFilter = { categoryBits = 2, maskBits = 2}

This way the walls don’t collide with eachother and the ships don’t collide with eachother but the ships collide with walls and viceversa.
[import]uid: 8192 topic_id: 1811 reply_id: 5457[/import]

Nope. Thought I figured it out but no luck.

I set my filters as global variables just to make sure I am not messing something up.

ANSCA. Please Help.

Thanks
[import]uid: 8192 topic_id: 1811 reply_id: 5474[/import]

I took a look at your example and if you use that website I provided, you’ll see why your ships are still bumping into eachother.

With these values:

local wallCollisionFilter = { categoryBits = 1, maskBits = 1}
local shipCollisionFilter = { categoryBits = 2, maskBits = 2}

When you enter 2 in that website, you’ll see that the maskBit value of 2 collides with categoryBits 1 and 2. Your ship is categoryBit 2 so that’s why it’s colliding with other ships. And in fact, your walls would also collide with other walls since categoryBit 1 falls into maskBit 1.

Along the way, I stopped trying to figure out the logic behind WHY certain category bits fall into maskBits and just decided hey, I’ll just use that website and it’ll tell me. Understanding would involve too much time in learning about binary values, bits, etc. Apart from that, Corona actually makes it pretty easy to implement.

Use that website, it’ll save a lot of time and headache!

Here is is again: http://www.exploringbinary.com/binary-converter/ [import]uid: 7849 topic_id: 1811 reply_id: 5495[/import]

This is also one of the areas that confused me A LOT when I first started with Corona, and really couldn’t find any help anywhere either.

It’s still really confusing, but I got it to work, so I’ll try my best to explain it to you.

First, if you know nothing about bits, binary values, etc. (like me), then shed any kind of logic you possess when trying to figure it out. It simply doesn’t make any logical sense without prior knowledge of binary values, how they work, etc.

Then…

Go to THIS webpage and bookmark it (VERY useful for this):

http://www.exploringbinary.com/binary-converter/

From there, you can enter a maskBit value (such as 2, 4, 6, etc) and see what categoryBits it will collide with (will be explained soon).

PRACTICAL EXAMPLE

Now, let’s say for example you have MONSTERS, a PLAYER, and ITEMS.

MONSTERS should collide with only players, PLAYER should collide with both MONSTERS and ITEMS, and ITEMS should collide only with the PLAYER.

MONSTERS will have the following settings:

  • categoryBits = 2

  • maskBits = 4

NOTE: maskBits of 4 will collide with categoryBits 1 and 3 (use that webpage I provided)

PLAYER will have the following settings:

  • categoryBits = 1

  • maskBits = 3

NOTE: maskBits of 3 will collide with categoryBits 1 and 2

ITEMS will have the following settings:

  • categoryBits = 2

  • maskBits = 4

NOTE: maskBits of 4 will collide with categoryBits 1 and 3.

Also note that I didn’t test the above example, but that’s the exact process I used to get collision masks working in my game.

According to the notes I provided under each one, you’ll see that MONSTERS will collide with the PLAYER (categoryBit 1), but not ITEMS (categoryBit 2). The PLAYER will collide with both monsters and items (it would also collide with other player objects, but for the sake of this example there is only 1 player). ITEMS will collide only with the PLAYER but not MONSTERS.

If you use that webpage I provided, you can see how it works a little easier. Plug in a number into the first field (it’s labeled decimal, but just put in a whole number like 6) and then click ‘Convert’. Ignore the binary field, and look to the right where it says ‘Num Digits’ and those are the ‘categoryBits’ that that particular maskBit will collide with.

So for example, type in 6 and it’ll output 1.0 to 3.0. That means the maskBit of 6 will collide with anything that has a categoryBit of 1 or 3.

From there, you should be able to figure it out based on your game’s requirements. Like I said, I didn’t test that EXACT example, but I did use the same method to get it working in my game. Please let me know if my example is flawed and I’ll work to fix it.

Hope that helps! [import]uid: 7849 topic_id: 1811 reply_id: 5494[/import]

@jonbeebe Thank you so much for the help. Unfortunately it’s still not working. Ships are still colliding with eachother. This is driving me nuts!

This is what I have for the filters
local wallCollisionFilter = { categoryBits = 1, maskBits = 2} – Should collide only with 1 and 2
local shipCollisionFilter = { categoryBits = 2, maskBits = 4} – Which according to your method should only collide with 1 and 3

[import]uid: 8192 topic_id: 1811 reply_id: 5509[/import]

Finally got it. Had syntax error with calling the filter name and then used the following
wallCollisionFilter = { categoryBits = 2, maskBits = 1} – Collides with 1 only
shipCollisionFilter = { categoryBits = 1, maskBits = 10} – Collides with 2 and 4

Thanks again
[import]uid: 8192 topic_id: 1811 reply_id: 5511[/import]

Glad it worked out! [import]uid: 7849 topic_id: 1811 reply_id: 5530[/import]