modules/world: add friction system to Actor2D

This commit is contained in:
Kazhnuz 2019-04-28 09:31:10 +02:00
parent 3ce567b113
commit c43317bfe2

View file

@ -61,6 +61,9 @@ function Actor2D:initPhysics(x, y, w, h, isSolid)
self.xsp = 0
self.ysp = 0
self.xfrc = 0
self.yfrc = 0
self.isSolid = isSolid or false
self:setFilter()
@ -105,6 +108,13 @@ end
function Actor2D:autoMove(dt)
local newx, newy, cols, colNumber = self:move(self.x + self.xsp * dt, self.y + self.ysp * dt)
-- apply after the movement the friction, until the player stop
-- note: the friction is applied according to the delta time,
-- thus the friction should be how much speed is substracted in 1 second
self.xsp = utils.math.toZero(self.xsp, self.xfrc * dt)
self.ysp = utils.math.toZero(self.ysp, self.yfrc * dt)
end
function Actor2D:move(dx, dy)