modules/world: add collision response system
This commit is contained in:
parent
7f8234b7f7
commit
0d25dbd839
1 changed files with 12 additions and 0 deletions
|
@ -113,10 +113,22 @@ function Actor2D:autoMove(dt)
|
||||||
-- note: the friction is applied according to the delta time,
|
-- note: the friction is applied according to the delta time,
|
||||||
-- thus the friction should be how much speed is substracted in 1 second
|
-- 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.xsp = utils.math.toZero(self.xsp, self.xfrc * dt)
|
||||||
self.ysp = utils.math.toZero(self.ysp, self.yfrc * dt)
|
self.ysp = utils.math.toZero(self.ysp, self.yfrc * dt)
|
||||||
end
|
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)
|
function Actor2D:move(dx, dy)
|
||||||
local cols, colNumber
|
local cols, colNumber
|
||||||
self.x, self.y, cols, colNumber = self.world:moveActor(self, dx, dy, self.filter)
|
self.x, self.y, cols, colNumber = self.world:moveActor(self, dx, dy, self.filter)
|
||||||
|
|
Loading…
Reference in a new issue