[Hardon Collider] How to resolve collisions properly

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
MadByte
Party member
Posts: 485
Joined: Fri May 03, 2013 6:42 pm
Location: Germany

[Hardon Collider] How to resolve collisions properly

Post by MadByte » Tue Mar 13, 2018 4:29 pm

Hey guys,

it's very likely that I'm missing something, but I can't find any good way to resolve my collisions using Hardon Collider. The collision detection part works like a charm, but I don't get how I'm supposed to "connect" the colliding shapes to my actual in-game entities in order to resolve collisions between let's say different types of objects. Here's an example:

Code: Select all

-- main.lua
-- Pseudo code btw

local HC	= require("HC")

local Platform	= Platform() -- type = "Platform"
local Player	= Player() -- type = "Player"
local Enemy	= Enemy() -- type = "Enemy"



function love.load()
    	-- add shapes to my entities
	Platform:addShape(HC.rectangle(...))
	Player:addShape(HC.rectangle(...))
	Enemy:addShape(HC.rectangle(...))
end


function love.update(dt)
	-- update entities
	Platform:update(dt)
	Player:update(dt)
	Enemy:update(dt)
end


function love.draw()
	-- draw entities
	Platform:draw()
	Player:draw()
	Enemy:draw()
end

...



-- Player.lua

local HC = require("HC")

...

function Player:updateCollisions(dt)
	-- check for collisions
	for shape, delta in pairs(HC.collisions(self.shape)) do
		-- now I need to know what type the other entity is to resolve the collision
		-- because the player ie should respond differently to platforms (ie "land on") then to enemies (ie "add damage")
		if otherEntityType = "Platform" then
			-- Do stuff
		elseif otherEntityType  = "Enemy" then
			-- do other stuff
		end
	end
end

...
So, what I expect to get from the lib is a way to differentiate between object types in order to resolve my collisions. With love.physics ie you can add data to a shape using shape:setData(data)... and bump takes a table (world:add(OBJECT, x, y, w, h) which then gets returned if a collision occurs. As workaround I already altered the library so that it takes an additional reference to the object that "owns" the shape (similar to bump), but I guess that's not what I'm supposed to do here. :awesome:

How would you guys solve this problem? Thanks in advance.

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

Re: [Hardon Collider] How to resolve collisions properly

Post by 4aiman » Sat Mar 17, 2018 4:33 pm

HC isn't designed to keep tabs on anything. So you should come up with your own way of storing data.
Creating a wrapper to swap underlying collision lib on-the-fly may be a good idea.
I'd use HC only in the case I absolutely need non-aabb collisions.

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests