Colors Collison

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
NickRock
Citizen
Posts: 76
Joined: Thu Dec 25, 2014 9:33 pm
Location: Earth
Contact:

Colors Collison

Post 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)
Weeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeooow!!
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Colors Collison

Post by Karai17 »

Not really, no.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: Colors Collison

Post 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.
User avatar
Beelz
Party member
Posts: 234
Joined: Thu Sep 24, 2015 1:05 pm
Location: New York, USA
Contact:

Re: Colors Collison

Post 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

Code: Select all

if self:hasBeer() then self:drink()
else self:getBeer() end
GitHub -- Website
User avatar
Inny
Party member
Posts: 652
Joined: Fri Jan 30, 2009 3:41 am
Location: New York

Re: Colors Collison

Post 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.
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Colors Collison

Post 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:
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 4 guests