modules/world: add collision response system

This commit is contained in:
Kazhnuz 2019-04-28 11:06:07 +02:00
parent 7f8234b7f7
commit 0d25dbd839

View file

@ -113,10 +113,22 @@ function Actor2D:autoMove(dt)
-- note: the friction is applied according to the delta time,
-- thus the friction should be how much speed is substracted in 1 second
self:solveAllCollisions(cols)
self.xsp = utils.math.toZero(self.xsp, self.xfrc * dt)
self.ysp = utils.math.toZero(self.ysp, self.yfrc * dt)
end
function Actor2D:solveAllCollisions(cols)
for i,v in ipairs(cols) do
self:collisionResponse(v)
end
end
function Actor2D:collisionResponse(collision)
-- here come the response to the collision
end
function Actor2D:move(dx, dy)
local cols, colNumber
self.x, self.y, cols, colNumber = self.world:moveActor(self, dx, dy, self.filter)