[Hardon Collider] How to resolve collisions properly
Posted: 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:
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.
How would you guys solve this problem? Thanks in advance.
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
...
How would you guys solve this problem? Thanks in advance.