improvement(world): separate future position and friction from autoMove
This commit is contained in:
parent
c57f372648
commit
049213000a
1 changed files with 11 additions and 0 deletions
|
@ -59,6 +59,7 @@ function Actor2D:autoMove(dt)
|
||||||
self.onGround = false
|
self.onGround = false
|
||||||
self:applyGravity(dt)
|
self:applyGravity(dt)
|
||||||
|
|
||||||
|
local dx, dy = self:getFuturePosition(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
|
-- apply after the movement the friction, until the player stop
|
||||||
|
@ -67,6 +68,16 @@ function Actor2D:autoMove(dt)
|
||||||
|
|
||||||
self:solveAllCollisions(cols)
|
self:solveAllCollisions(cols)
|
||||||
|
|
||||||
|
self:applyFriction(dt)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Actor2D:getFuturePosition(dt)
|
||||||
|
local dx, dy
|
||||||
|
dx = self.x + self.xsp * dt
|
||||||
|
dy = self.y + self.ysp * dt
|
||||||
|
end
|
||||||
|
|
||||||
|
function Actor2D:applyFriction(dt)
|
||||||
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
|
||||||
|
|
Loading…
Reference in a new issue