Page 1 of 1

Colors Collison

Posted: Tue Nov 03, 2015 9:05 pm
by NickRock
Is it possible to detect if an object collides with an other that has a specific color (or outline color) without using any other collision detection techniques? (e.g. AABB)

Re: Colors Collison

Posted: Tue Nov 03, 2015 9:22 pm
by Karai17
Not really, no.

Re: Colors Collison

Posted: Tue Nov 03, 2015 9:49 pm
by bobbyjones
You could write some code that can take an image and generate a list of polygons or triangles that would give a more accurate collision box without having to check the color of each pixel. There is programs like this that exist and you could probably adapt them to work with your choice collision lib. I personally used it to export bounding boxes for love.physics. This is the tool I used https://www.codeandweb.com/physicseditor it may be possible to make your own.

Re: Colors Collison

Posted: Wed Nov 04, 2015 2:44 am
by Beelz
I would just assign collision groups by giving each object's table another variable.

Code: Select all

-- In collision detection function...

if object1.colGroup == "red" and object2.colGroup == "green" then
    --  collide
end

Re: Colors Collison

Posted: Wed Nov 04, 2015 4:15 am
by Inny
I'm a fan of spatial-hashing.

Take a table, and assign each location on screen a value. 1 for top left. 16 for top right, 17 for just below top left, you get the idea. For a 16:9 aspect ratio, that's 144 cells. In each cell, have a table. Now, on each update, you clear those tables, and then iterate through your entities. Map them as best you can to the cells that they're overlapping with. Since all the cells will be the same size, this is easy math, but it's important that ALL of the cells the entity overlaps are mapped. In each mapped cell, add that entity to the back of the list. Now, for each entity, if you're adding it to a list that has anything else in that list, you collect those entities into another list.

Now, you have a short list of potential hits for each entity. You can AABB or any more expensive collision checks against the smaller set.

Re: Colors Collison

Posted: Wed Nov 04, 2015 11:53 am
by Roland_Yonaba
Inny wrote:I'm a fan of spatial-hashing.

Take a table, and assign each location on screen a value. 1 for top left. 16 for top right, 17 for just below top left, you get the idea. For a 16:9 aspect ratio, that's 144 cells. In each cell, have a table. Now, on each update, you clear those tables, and then iterate through your entities. Map them as best you can to the cells that they're overlapping with. Since all the cells will be the same size, this is easy math, but it's important that ALL of the cells the entity overlaps are mapped. In each mapped cell, add that entity to the back of the list. Now, for each entity, if you're adding it to a list that has anything else in that list, you collect those entities into another list.

Now, you have a short list of potential hits for each entity. You can AABB or any more expensive collision checks against the smaller set.
And in that respect, I might already have something ready. :awesome: