Collision Filters "Helper Chart"

45 replies [Last post]
User offline. Last seen 5 years 27 weeks ago. Offline
Joined: 4 Oct 2010

Hello all,

I'm posting the following explanation about Collision Filters as a help to the community in general, as a result of my own experiments. Some users, especially recent converts, have not yet used collision filters but it's an essential aspect to almost any game design. I created the attached "Collision Helper Chart" which I use for my own game designs... hopefully it can assist others too! The blank document can be downloaded from my website (link at the end of this post).


So, what are Collision Filters? Simply put, they're a method to determine what objects combine with other objects, or perhaps more importantly, what objects do not collide with others in a game. The official documentation explains Corona's method of accomplishing this, which varies from other SDKs, but I created a chart to assist in the issue.

Here's a chart and list of steps following the classic "Asteroids" game example...


  1. Observe the "bits" (numbers) in the very top row. 1 to 512, in binary numbers. You can go as high as "32768" (16 places) but I stopped the chart at 512 which should be enough for most people. These "bits" are how Corona determines collision filters.
  2. Observe the first row. It has two sub-rows: "catg." and "cl.w/". These mean "category" and "collides with" respectively.
  3. For each object type in your game (i.e. "asteroid", pick one bit number. Place a circled X in that column. This bit number should be unique and not repeated for other objects under most circumstances! (There are probably advanced situations where you might duplicate category bits or even assign more than one to an object, but don't worry about it now)
  4. Next, ask yourself: "can this object collide with others of its type?" If yes, then place an X directly below in the "collides with" row. In the example, notice that asteroids can collide with other asteroids.
  5. Move down the rows of other objects in your game. For every object that "asteroids" can collide with, place an X in the "collides with" row for that object. Asteroids can collide with player_ship and alien_ship, so both of those get an X in their respective row/column. If it's not obvious already, keep the columns ordered: Asteroids have bit "2" as their category, so stay within that column for anything asteroids should collide with (I colored the chart entries to make it clearer).
  6. Move to the next game object and repeat. IMPORTANT! You must work back UP the chart, not just down! If two objects are intended to collide, both must be marked properly or the collision will not function! So, take the item pair of asteroid and player_ship, which should always collide: "asteroid: category" is marked in "player_ship: collide with" AND "player_ship: category" is marked in "asteroid: collide with". If you fail to mark both corresponding factors, the collision will not happen!
  7. When you've done all of your objects, simply add the bits across every row to determine sums.
  8. For each collision filter, you need these sums as follows, near the top of your main.lua file.

local asteroidCollisionFilter = { categoryBits = 2, maskBits = 7 }
local playerCollisionFilter = { categoryBits = 1, maskBits = 6 }
local alienCollisionFilter = { categoryBits = 4, maskBits = 7 }

categoryBits is the sum from the "category" row for that object.
maskBits is the sum from the "cl.w/" row for that object.

  1. Later, in your physics body declarations, specify the collision filter. Obviously, define the proper filter for every object in your game, as declared near the top of your game code.

local asteroid = display.newImageRect( [displayGroup], "asteroid.png", 32, 32 )
physics.addBody( asteroid, { density=2.9, friction=0.5, bounce=0.3, radius=16, filter=asteroidCollisionFilter } )

That's it! Remember the basic rules of collisions and body types. "Dynamic" bodies react physically with other "dynamic" or "static" bodies, but not with "kinematic" bodies. While confusing at first, it will soon make complete sense.

Anyway, hopefully this helps some new Corona users, or even gives veterans a more visual way to calculate collision filters. If anybody at Ansca or in the community sees any errors in my description, please let me know! I'm not an Ansca staff member or Corona expert; all of this is just a result of my own personal testing and experimentation. :)

And here's a link to the blank "chart" document in PDF format. You can download it from my website and print it for your own use: Collision Filter Helper Chart (PDF)


Brent Sorrentino
Ignis Design LLC


User offline. Last seen 20 weeks 6 days ago. Offline
Joined: 31 Oct 2009

Hi that was a very helpful document, thanks for posting it. I am sure a lot of new developers will appreciate it.

User offline. Last seen 6 years 40 weeks ago. Offline
Joined: 26 Jul 2010

This has always confused me like no other, and this chart you created (as well as the explanation of how to use it) is nothing short of AMAZING.

Thanks Brent, I'm definitely going to link to this from my blog once I test it out in my current project.

UPDATE: I posted a link from my blog. I know I ran into this late, but thanks again Brent, it worked for me the first time around :-)

Jonathan Beebe

User offline. Last seen 5 years 27 weeks ago. Offline
Joined: 4 Oct 2010

Thanks Jon!

Nice to hear that it worked perfectly the first time around. I hope others will link to it from your blog. I think Ansca's implementation of collision filters is incredible (much better than Torque2D's filters in my humble opinion), but Ansca hasn't really documented or explained it very well... so ideally, others can follow my chart method and use it for their games.


carlos m. icaza
User offline. Last seen 8 years 24 weeks ago. Offline
Joined: 22 Jun 2009

I been out of the forums for a few days due to my travels and I just came across this.

Wow. Fantastic.

Thanks @ignisdesign for documenting it !

We should get our **s together and make our docs much better. I know we lack in that dept.

Thanks again !


User offline. Last seen 9 years 37 weeks ago. Offline
Joined: 16 Sep 2009

As a start, I added a link to this post in the collision filter docs here:

Thanks, @IgnisDesign!

User offline. Last seen 6 weeks 5 days ago. Offline
Joined: 11 Nov 2009

Nice work. I usually make a right mess of my collision filter, so thanks.

User offline. Last seen 3 years 41 weeks ago. Offline
Joined: 28 Sep 2010

This has been very helpful, thank you very much!

User offline. Last seen 9 years 32 weeks ago. Offline
Joined: 27 Dec 2010

Is there any way to temporarily suspend all collisions for a physical object without destroying and recreating it as nonphysical? I was trying to suppress collision detection on an object being dragged, but when not being dragged would collide as normal. Changing the collision filter before and after the drag doesn't seem to work.

User offline. Last seen 6 years 40 weeks ago. Offline
Joined: 26 Jul 2010

@hoplite: Try this...

For disabling physics on a specific object:

myObject.isBodyActive = false

Obviously, change myObject to the object you want to stop registering collisions, etc.

Alternatively, you can use:

myObject.isSensor = true

The above will still register collisions, but will not "bounce" off of anything (things will pass through it, but you can still handle collision events).

Hope that helps! I use both of the above A LOT so I can't imagine what it would be like not knowing about them.

User offline. Last seen 9 years 32 weeks ago. Offline
Joined: 27 Dec 2010

Worked like a charm, @jonbeebe! Much appreciated.

User offline. Last seen 8 years 33 weeks ago. Offline
Joined: 19 Jan 2011


Is it possible to alter the collision mask at runtime?

Based on the object's game state, i'd like it to collide with different categories.


Found the answer

User offline. Last seen 8 years 35 weeks ago. Offline
Joined: 26 Jan 2011

So I may have too much time on my hands but I loved this detailed explanation of filters so much I turned the pdf file into a full Google spreadsheet

Heres the link:

You can't edit this copy, but if you're signed into your Google account you can click File > Make a Copy

There is an example sheet along with a template sheet. I hope someone else can enjoy this spreadsheet.

@IgnisDesign Thanks for the post

User offline. Last seen 5 years 27 weeks ago. Offline
Joined: 4 Oct 2010

CSteh this is awesome! Thanks for enhancing the chart, especially with higher bit numbers than I provided on the PDF (useful for those people designing intensive games with tons of collision rules).

I'm glad this document is helpful for so many game developers. :)

Brent Sorrentino
Ignis Design

Stephen Lewis
User offline. Last seen 4 years 23 weeks ago. Offline
Joined: 24 Sep 2010

Just incredibly useful. Thanks Ignis for chart and explanation, and thanks CSteh for the handy google doc.

User offline. Last seen 9 years 14 weeks ago. Offline
Joined: 11 Mar 2011

Hey great post, found it damn simple and easy to use the collision filters. Had just one query and that is is it possible to animate these objects as well.
I tried doing so but either,
1) the collision filter works in which case the objects do not get animated or
2) the frame animation code works in which case the objects pass through each other without collision

I need the object to collide (using collision filters) and at the same time keep moving(using frame animation) until an object is tapped on, in which case that object becomes stationary.

Firstly is this possible.

If yes how can I do it. I am new to corona so would really appreciate the help.

Please help me. I have my jury in a few days and I really need this game to work.

User offline. Last seen 5 years 27 weeks ago. Offline
Joined: 4 Oct 2010

Good to hear that the Collision Chart helped!

About your issue: it's definitely possible. :) I have animated objects (using sprite sheets) moving about my game and using collision filters too.

I don't think it makes a difference, but in my game (for the main character) I configured the animation parameters first, then I declared the physics body and collision filter after this.

Can you post some sample code so others can see what might be happening?

Brent Sorrentino
Ignis Design

User offline. Last seen 9 years 14 weeks ago. Offline
Joined: 11 Mar 2011

Yes, surely

Hey Guys I am making a game using corona sdk and so needed help with the lus code. In this program there are bubbles floating across the screen and colliding with each either as well as with the walls of the screen.

I am using 'Collision Filter' for the collisions and the masking operation and it is working well. But in this game I want a bubble to continuously move unless and until it is tapped upon. I thought of using the frame animation to animate each bubble and then add a separate function that will make it stationary when tapped.

But the problem is that at a time only 1 program seems to wrok fine. So,
1) either the bubbles collide, fall down, bounce against wall and eventually rest down.
2) The bubbles continuously keep moving across the screen, without colliding against each other, and instead pass through the other bubbles

What should I do to animate and inanimate(on tapping that bubble) a colliding bubble.

My code is below,

borderCollisionFilter = { categoryBits = 1, maskBits = 2 } -- collides with (4 & 2) only
local borderBodyElement = { bounce=1.0, filter=borderCollisionFilter }

local borderTop = display.newRect( 0, 0, 480, 1 )
borderTop:setFillColor( 0, 0, 0, 0) -- make invisible
physics.addBody( borderTop, "static", borderBodyElement )

local borderBottom = display.newRect( 0, 318, 480, 1 )
borderBottom:setFillColor( 0, 0, 0, 0) -- make invisible
physics.addBody( borderBottom, "static", borderBodyElement )

local borderLeft = display.newRect( 0, 0, 1, 320 )
borderLeft:setFillColor( 0, 0, 0, 0) -- make invisible
physics.addBody( borderLeft, "static", borderBodyElement )

local borderRight = display.newRect( 480, 1, 1, 320 )
borderRight:setFillColor( 0, 0, 0, 0) -- make invisible
physics.addBody( borderRight, "static", borderBodyElement )


--local r1=30
--local r2=30

--local xdir1 = math.random(-3,5)
--local ydir1= math.random(-1,3)

--local xs1 = 2
--local ys1 = 3.5

--local x1 = 50
--local y1 = 350

local bubbleCollisionFilter = { categoryBits = 2, maskBits = 7 }
local bubble = {bounce=0.94, radius=18,filter = bubbleCollisionFilter }


--bubble.x = x1
--bubble.y = y1

--local sT = display.screenOriginY
--local sB = display.viewableContentHeight + display.screenOriginY
--local sL = display.screenOriginX
--local sR = display.viewableContentWidth + display.screenOriginX

--local function an1(event)

--x1 = x1 + ( xs1 * xdir1 );
--y1 = y1 + ( ys1 * ydir1 );

--if ( x1 > sR - r1 or x1 < sL + r1 ) then
-- xdir1 = xdir1 * -1;

--if ( y1 > sB - r1 or y1 < sT + r1) then
--ydir1 = ydir1 * -1;

--bubble:translate( x1 - bubble.x, y1 - bubble.y)

--bubble.angularVelocity = 100
--bubble:applyForce( 185, 0, bubble10.x, bubble10.y )


--Runtime:addEventListener( "enterFrame", an1 );


local bubble1 = display.newImage( "bubble.png", 50, 50 )
physics.addBody( bubble1, bubble )

local bubble2 = display.newImage( "bubble.png", 100, 230 )
physics.addBody( bubble2, bubble )

local bubble3 = display.newImage( "bubble.png", 180, 200 )
physics.addBody( bubble3, bubble )

local bubble4 = display.newImage( "bubble.png", 90, 30 )
physics.addBody( bubble4, bubble )


minionCollisionFilter = { categoryBits = 4, maskBits = 2 }
minionBodyElement = { bounce=0.8, filter=minionCollisionFilter }

local c1 = display.newImage("str-minion-small.png")
physics.addBody( c1, "static", minionBodyElement )

local c2 = display.newImage("str-minion-mid.png")
physics.addBody( c2, "static", minionBodyElement )

local c3 = display.newImage("str-minion-big.png")
physics.addBody( c3, "static", minionBodyElement )


local function spawnDisk( event )
local phase = event.phase
local volumeBar = display.newLine( 0, 0, 1, 0 )
volumeBar.y = 400
volumeBar.x = 20
local v = 20*math.log(r:getTunerVolume())
local MINTHRESH = 30
local LEFTMARGIN = 20
local v2 = MINTHRESH + math.max (v, -MINTHRESH)

v2 = (display.contentWidth - 1 * LEFTMARGIN ) * v2 / MINTHRESH
volumeBar.xScale = math.max ( 20, v2 )

local l = volumeBar.xScale
local cnt1 = 0
local cnt2 = 0
local cnt3 = 0
local ONE =1
local val = event.numTaps

if "ended" == phase then
if l > 50 and l <=150 then
c1.x=math.random( 10, 450 )
c1.y=math.random( 10, 300 )
physics.addBody( c1, { density=1, radius=10.0 } )
cnt1= cnt1+ ONE
return c1

elseif l > 100 and l <=250 then
c2.x=math.random( 10, 450 )
c2.y=math.random( 10, 300 )
physics.addBody( c2, { density=2, radius=30.0 } )
cnt2= cnt2+ ONE
return c2

elseif l >=250 then
c3.x=math.random( 40, 450 )
c3.y=math.random( 40, 300 )
physics.addBody( c3, { density=2, radius=50.0 , bounce=0.0 } )
cnt3= cnt3+ ONE
return c3

buzzR:addEventListener( "touch", spawnDisk ) -- touch the Button to create minions


In this code the bubbles need to collide with,
1) the walls (c=1)
2) each other (c=2)
3) minions (c=4)

Also these bubbles need to move continuously(at a slow pace) across the screen without coming to a rest, until that bubble is tapped.

In the above code the filters works perfectly the animation does not. I have commented those codes. Tried using the frame animation function for the bubble construct.

Also need a way by which when I tap a bubble that bubble becomes stationary.

Really appreciate the help.

Thanks Brent :).

User offline. Last seen 5 years 27 weeks ago. Offline
Joined: 4 Oct 2010

This helps clarify what's going on, somewhat. :)

Without dissecting your actual code, I just have a few suggestions on how you might tackle some of the tasks mentioned...

1) For the bubbles, I would suggest you use Sprite Sheets for their animation (they are animating in some way, correct?). I assume all of the bubbles will use the same basic animation, so you can create one sprite sheet in the beginning and every bubble can reference it. If you have multiple bubble types (different colors, for example), you just configure different sprite definitions within that sprite sheet. Sprite sheets might seem complicated at first but they're very memory-efficient and Corona documents their usage nicely.

2) Each bubble is a physical object, of course. For each one, I would store/link its velocity and direction directly to the bubble, as in "thisBubble.xVel = 10" (xVel could be whatever name you want: xVeloc, xVelocity, xV, basically anything that doesn't conflict with another variable name or Corona API name).

The reason for storing these values is to stop/resume the bubbles on tap. When the bubble is tapped, you just set the velocities to 0. Then on "resume" you read those stored values and send the bubble moving on the same path/speed it was on before.

By using sprite sheets (above) you can simply pause the animation to make the bubble look "stopped" and then resume its animation when needed.

Does this help somewhat? As with most programming SDKs, there are usually multiple ways to accomplish a certain task. This is how I would program your scenario, personally. :)


User offline. Last seen 9 weeks 21 hours ago. Offline
Joined: 17 Jan 2011


im having trouble with using the [displayGroup] funtion. i tired using it in my game but i can't output onscreen the image.

local asteroid = display.newImageRect( [displayGroup], "asteroid.png", 32, 32 )
physics.addBody( asteroid, { density=2.9, friction=0.5, bounce=0.3, radius=16, filter=asteroidCollisionFilter } )

my coded version looked like this
local player = display.newImage("assets/graphics/player.png")
physics.addBody( player, "kinematic",  { density=2.9, friction=0.5, bounce=0.3, radius=16, filter=playerCollisionFilter } )
player.x = 150
player.y = 375

i wasn't able to find any info regarding the displaygroup and the benefits they offer.

any help would be greatly appreciated.

User offline. Last seen 5 years 27 weeks ago. Offline
Joined: 4 Oct 2010

Scroll down about halfway and look for the "Groups" heading:

Display groups are 100% essential to development. They act as "layers" to correctly position images behind or in front of other images. They also act as ways to group and manage a whole series of images and perform an action on the entire set with one command, like move 15 related items across the screen.

Any place you see "[displayGroup]" in the API reference, it's talking about the group to insert this object into (a group you've defined already). Otherwise it will be put onto the "stage" which is a master display group in itself, but you'll need more control than just this one stage layer.

If you're just starting with Corona, follow through some of the basic tutorials thoroughly. It takes some time and it's a little tedious at points, but it's worth every second.

User offline. Last seen 9 years 14 weeks ago. Offline
Joined: 11 Mar 2011

Hi Brent,
firstly thanks for the help so far. But the problem is that I am still kind of stuck.

The reason for this is that I am not sure if configuring a sprite sheet uniquely for each bubble would give me the effect I need.

You must have seen the fishies example,

I need the bubbles to move across the screen exactly in the way the fishes do. And on clicking a bubble it gets stationary and it change color similar to that in the fishies example.

In fact I initially thought of using that code and modifying it but, the issue is that physics does not work on group objects(it appears as though on a separate layer). So the bubbles do not collide with each other or with the minions ( spwaning objects)

User offline. Last seen 5 years 27 weeks ago. Offline
Joined: 4 Oct 2010

I've seen the Fishies example. The "problem" with this example, in my opinion, is that it uses constant Runtime tracking of every fish's X and Y position, and then when a fish reaches the edge of the screen, it does something to that fish (changes its direction). This is not necessarily bad coding, but if you're using physics bodies on your bubbles already, it's better to take advantage of the physics system and all its powers. :)

Stopping and re-starting the bubbles could be done as I outlined in my post above (store X and Y velocity, set them to 0,0 on first tap, resume to stored value on next tap).

The bubbles can still be sprites, based on just ONE sprite sheet, not multiple sheets. You define the sheet once at the start and all bubbles can access it. This is the beauty of sprite sheets. You could even have 3 colors of bubbles in 3 frames within the sheet. Frame 1 is "normal" (aqua?), frame 2 is "green", frame 3 is "red", or whatever. On clicking a bubble, you just declare its frame and it appears as the color bubble you need.

You could even make animating bubbles in this fashion. Let's say the bubble has 3 frames of animation. Your sprite sheet could be set up like this (in numbered frame order):


"Normal" animation would be cycling constantly between frames 1 and 3. You define this as an individual sprite (sprite.add) within the sprite sheet/set. "Green" animation would cycle between frames 4-6, "Red" between 7-9. This is all very simple to set up and change during runtime, and you can control speed and looping too (cycle, back-and-forth, number of loops, etc.)

User offline. Last seen 9 years 14 weeks ago. Offline
Joined: 11 Mar 2011

Hmm ok, well will definitely try the approach you have suggested :) .

But since am new to corona I am not very clear with the syntax. Nonetheless I want to try and will post with the same. If I have some issue will let you know. And you could tell me what in my code is not working. Would really appreciate all the help since I have none as of now.

Anyways take care and thanks a lot Brent :).

User offline. Last seen 9 years 14 weeks ago. Offline
Joined: 11 Mar 2011

Hey hi brent, tried working on your suggestion but frankly due to my lack of coding experience I was unable to do it. I don't know where to start or what syntax to follow. I tried searching for reference with regards to collision on sprites and how to configure sprites for each bubble, here again am lost. Tried going through the horse animation code. But unlike in that I need the bubbles to move across the screen I don't know(syntax) how to achieve that using the sprites logic. And my biggest challenge is how to link the sprites and collision filters :( . I hope I am not asking for a lot. I really want to learn corona, but right now just blank and am unable to write code that will work. My jury is in this week, scared I will get an F. Could I mail you with regards to my queries? Sorry for all the trouble :(.

User offline. Last seen 5 years 27 weeks ago. Offline
Joined: 4 Oct 2010

It's tricky to learn this stuff, and sprite sheets are a more advanced topic. Since I (and most of us here) promote and truly enjoy Corona, we'd like you to stick around and keep using it. :) I'm too busy on my own projects to actually "write code" for you, but e-mail me and I can send you some snippets of code from my own projects which should help, specifically using sprite sheets.


User offline. Last seen 9 years 9 weeks ago. Offline
Joined: 19 Apr 2011

IS there anyway possible where we can add the collision filter later in a function ??
User offline. Last seen 31 weeks 6 days ago. Offline
Joined: 23 Oct 2010

Just a small hint -if you don't want to hardcode your collision flags in several places throughout your code and to avoid the hassle of calculating the sum of all those bits manually, you can use kind of "constants", like below. It's very clear and also allows to change the object categories and collision behaviour simply by editing those few lines at any time:

On top of your main.lua

-- DEFINE CATEGORIES (USE 1,2,4,8,16...)
TYPE_SHIP     = 1
TYPE_UFO      = 4
TYPE_SHOT     = 8
collisionFilter_Ship  = { categoryBits = TYPE_SHIP , maskBits = TYPE_COMET + TYPE_UFO }
collisionFilter_Comet = { categoryBits = TYPE_COMET, maskBits = TYPE_SHIP  + TYPE_SHOT + TYPE_COMET }
collisionFilter_UFO   = { categoryBits = TYPE_UFO  , maskBits = TYPE_SHIP  + TYPE_SHOT }
collisionFilter_Shot  = { categoryBits = TYPE_SHOT , maskBits = TYPE_COMET + TYPE_UFO  }

Then, anywhere in your game (in a module, for example), use:

filter = _G.collisionFilter_Comet


physics.addBody( Comet, { density=2.9, friction=0.5, bounce=0.3, radius=16, filter= _G.collisionFilter_Comet} )

User offline. Last seen 7 years 9 weeks ago. Offline
Joined: 28 Mar 2011

Here is my take on managing collision filter..

Download link :

User offline. Last seen 7 years 14 weeks ago. Offline
Joined: 11 Apr 2011


awesome! thanks for sharing

User offline. Last seen 8 years 38 weeks ago. Offline
Joined: 9 Feb 2011

Great Tutorial! Thank you so much!

User offline. Last seen 7 years 24 weeks ago. Offline
Joined: 19 Jun 2011

Just wanted to add, that if you DON'T supply a collision filter, the object acts as if it has a category bit of 1, and collides with EVERYTHING ELSE. Or in other words, it acts as if it has filter = { categoryBits = 1, maskBits = 65535 }.

User offline. Last seen 6 years 27 weeks ago. Offline
Joined: 11 Mar 2011

Hi all,

firstly thanks for this post, it is very helpful. Although i don't have a personal need for the filtering yet (my objects crash into everything) i am interested in the fact that isSensor should still register collisions.

Basically my issue is that i have an object that performs a function when collided with and it's working 100%, then i wanted this object to be moveable but if a user moves it over another object i don't want any action to occur. I accomplished this by using isSensor while the object is being dragged.

But that means that while it the object is a sensor there's no collision detection happening, and i need it to happen to stop the user from placing the object on top of another object (when he releases the object i don't want to allow him to put it directly on top of another object).

I hope that made sense, basically while the object is being dragged i make it a sensor, then when the phase ends i change it back, but i need a way to stop it from being placed on other objects.

Thanks for all the help!

User offline. Last seen 5 years 27 weeks ago. Offline
Joined: 4 Oct 2010

Hi marioanam,

If I understand correctly: you have something like a stack of "bricks" which the user can move around. During the "drag" stage, the user can move a brick anywhere, and it won't collide with anything. But upon the "drop" (end phase) you want to ensure that the brick is not directly on top of another brick...

"But that means that while it the object is a sensor there's no collision detection happening"

Sensors still register hits. If your isSensor object isn't registering hits, then you might have configured your physics setup improperly. The TYPE of the object is VERY important in regards to this... "solid" objects react differently to "kinematic" objects, and it's even more fussy when you're dealing with sensors. I would suggest you experiment with each type to achieve the proper collisions.

For example, in my game, I think a "solid sensor" only reacts with another solid sensor, not a "kinematic sensor". It's weird and unfortunately I haven't determined how/what reacts with what in the sensor state, or why. Best of luck!

User offline. Last seen 6 years 27 weeks ago. Offline
Joined: 11 Mar 2011

Thanks for the reply, turns out i was just being stupid. I was registering preCollision events which don't work with Sensors.

Thanks for the help anyway, i can now at least move on!

User offline. Last seen 6 years 1 week ago. Offline
Joined: 13 Oct 2011

thank you so much for this informative post

User offline. Last seen 29 weeks 6 days ago. Offline
Joined: 23 Mar 2011

This was incredibly useful. Kept me from blowing my brains out. A big "Thank you".

User offline. Last seen 7 years 47 weeks ago. Offline
Joined: 20 Nov 2011

* UPDATE - new features added >

I created a utility tool to help generate collision filters quickly so you can copy/paste them into projects.

It's a very easy tool to use. Simply type your physics object/body names into the left coloum, then you'll see them repeated in the top columns. Note that the top column names serve only as reference so that you can make connections between your objects (visually)

So you then use the check boxes to select the object collisions (i.e. can it collide with itself -- in the case of a bunch of spawned green boxes for example -- or can it collide with other objects.

Once you've got all your collisions ticked, simply click in the right field for that row and the text string will auto-highlight... then copy/paste into your lua file. Viola! Quick and easy collision filters and this allows for rapid testing, tinkering and prototyping as well.

I have done the collision filter calculation process manually (on paper) and using excel spreadsheets in the past, but thought there must be a better and faster way. So I hope you enjoy this tool.

Demo video:



User offline. Last seen 7 years 9 weeks ago. Offline
Joined: 28 Mar 2011

I haven't used Corona for long time... but if I remember correctly you have to specify collision both ways.. that is if obj1 collide with obj2 , you have to specify it both ways.. (unless you have specific case)

The excel file I had created does this automatically.. Maybe you can add option to do that in your tool..

Otherwise nice utility there.. Also you can also give ability to copy all collision filter in one go instead of doing it one by one..

BPC Games
User offline. Last seen 3 years 45 weeks ago. Offline
Joined: 14 Feb 2012

Wow great explanation IgnisDesign, I was actually kind of surprised when it worked for me the first time.
Zanuka, your tool is perfect, thanks for making it! :)

Thank you both

User offline. Last seen 7 years 47 weeks ago. Offline
Joined: 20 Nov 2011

Ah yes I forgot to reply to IgnisDesign's comment about suggested fix... as I have released a couple updates since then. :-)

Thanks for the feedback BPC and glad you like the Collisionator tool!



User offline. Last seen 7 years 7 weeks ago. Offline
Joined: 18 Nov 2011

Great explanation Ignis! And great tool Zanuka!
And great discussion! This is extremely informative!.

I have just one question.
Imagine a platform game. You have a hero, there are enemies, and there is floor (everybody needs floor). I want the hero and enemies to collide with floor, have gravity applied, etc, so i made them as dynamic bodies. Floor is static. Now, i want to detect a "hit" when the enemy touches the hero, but i don't want them to collide. Can i set the enemy as a sensor? What should i do then when assigning maskBits? Should i "tick" the hero-enemy, enemy-hero checkboxes, or being a sensor just takes care of everything and i don't need to use collision filters?

I guess this is an absolutely ordinary scenario for a platformer game so i hope someone can help me soon! Thanks everybody for taking your time to read!
User offline. Last seen 4 years 30 weeks ago. Offline
Joined: 1 Apr 2012


I have just added a tiny but helpful module right here on Share your code.

- Markus

User offline. Last seen 4 years 13 weeks ago. Offline
Joined: 25 Jan 2011

SCteh - This is the best thing ever! Thanks a lot :)

User offline. Last seen 6 weeks 6 days ago. Offline
Joined: 16 Feb 2012

Absolutely fabulous,

Excellent write up, simple to understand and dispels the myth of how difficult this is.
Rock on!

User offline. Last seen 2 years 45 weeks ago. Offline
Joined: 21 Jun 2012

With regards to setting up collision filters I found it a breeze using Level Director ( .
It allows you to set the category for each object and then has a collision editor where you can tick which other objects it can collide with.
The export to LUA automatically deals with the physic and collision properties.
It is only for windows users but a great tool.

Viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.