diff --git a/gamecore/modules/world/actors/actor2D.lua b/gamecore/modules/world/actors/actor2D.lua index 250aa58..b6b3a31 100644 --- a/gamecore/modules/world/actors/actor2D.lua +++ b/gamecore/modules/world/actors/actor2D.lua @@ -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)