From 0d25dbd8392c967c3ff5d739fb0dbc724e3ec45b Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 28 Apr 2019 11:06:07 +0200 Subject: [PATCH] modules/world: add collision response system --- gamecore/modules/world/actors/actor2D.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/gamecore/modules/world/actors/actor2D.lua b/gamecore/modules/world/actors/actor2D.lua index b6b3a31..f26e505 100644 --- a/gamecore/modules/world/actors/actor2D.lua +++ b/gamecore/modules/world/actors/actor2D.lua @@ -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)