modules/world: add friction system to Actor2D
This commit is contained in:
parent
3ce567b113
commit
c43317bfe2
1 changed files with 10 additions and 0 deletions
|
@ -61,6 +61,9 @@ function Actor2D:initPhysics(x, y, w, h, isSolid)
|
||||||
self.xsp = 0
|
self.xsp = 0
|
||||||
self.ysp = 0
|
self.ysp = 0
|
||||||
|
|
||||||
|
self.xfrc = 0
|
||||||
|
self.yfrc = 0
|
||||||
|
|
||||||
self.isSolid = isSolid or false
|
self.isSolid = isSolid or false
|
||||||
|
|
||||||
self:setFilter()
|
self:setFilter()
|
||||||
|
@ -105,6 +108,13 @@ end
|
||||||
|
|
||||||
function Actor2D:autoMove(dt)
|
function Actor2D:autoMove(dt)
|
||||||
local newx, newy, cols, colNumber = self:move(self.x + self.xsp * dt, self.y + self.ysp * 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
|
end
|
||||||
|
|
||||||
function Actor2D:move(dx, dy)
|
function Actor2D:move(dx, dy)
|
||||||
|
|
Loading…
Reference in a new issue