[solved] How to exlude collision detection with a certain shape in HC (hardon collider)

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
4aiman
Party member
Posts: 248
Joined: Sat Jan 16, 2016 10:30 am

[solved] How to exlude collision detection with a certain shape in HC (hardon collider)

Post by 4aiman » Mon Jan 08, 2018 12:14 pm

Sorry if this has been answered over and over again, but the search here just won't obey...

Right now Ii'm using this

Code: Select all

       for shape, delta in pairs(game.world:collisions(bullet.hco)) do 
           if shape~=game.player.body then 
              del[#del+1] = i break               
           end
       end    
to detect whether I should/shouldn't delete a shape.
  • game.world is a HC instance
  • bullet.hco stores the game.world:point() result
  • game.player.body is the result of game.world:circle() and keeps tabs on the player.
I can't seem to figure out how to exclude a certain shape (immortal object or an owner of the bullet). The code above (obviously) doesn't work.

So... How can I tell a shape to ignore collisions with some particular object?

Thanks in advance!
Last edited by 4aiman on Thu Jan 11, 2018 1:15 pm, edited 1 time in total.

Ostego160
Prole
Posts: 14
Joined: Tue Oct 17, 2017 7:18 pm

Re: How to exlude collision detection with a certain shape in HC (hardon collider)

Post by Ostego160 » Mon Jan 08, 2018 8:19 pm

HC is such a lovely library, there's a couple ways to do it. Here's how I do it:

I have an ignore variable stored on each object in the world; each object in a table. Here we iterate through enemies.

Code: Select all

   for i=1,#enemies do
      local candidates = collider:neighbors(enemies[i].mask)			--Mask is a reference to the HC shape
      for other in pairs(candidates) do
         local collides, dx, dy = enemies[i].mask:collidesWith(other)		--Get the boolean event, and the collision resolution data
         if collides and not other.ignore then					--THIS IS WHAT YOU WANT, the check on other to ignore
            if other.type == 'static' or other.type == 'character' then		--Other additional checks
               enemies[i].mask:move(dx,dy)					--Collision Resolution
            elseif other.type == 'debris' then
               other:move(-dx,-dy)
            end
         end
      end
   end
Hope this helps my friend. :monocle:

User avatar
4aiman
Party member
Posts: 248
Joined: Sat Jan 16, 2016 10:30 am

Re: How to exlude collision detection with a certain shape in HC (hardon collider)

Post by 4aiman » Thu Jan 11, 2018 8:07 am

Thanks!
It turned out I had a typo somewhere, since after I unified all the names (now every object has hco property with a reference to HC shape) my code worked as well as yours!

Cheers! ^_^

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests