improvement(world): separate future position and friction from autoMove

This commit is contained in:
Kazhnuz 2019-06-27 21:29:49 +02:00
parent c57f372648
commit 049213000a

View file

@ -59,6 +59,7 @@ function Actor2D:autoMove(dt)
self.onGround = false
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)
-- apply after the movement the friction, until the player stop
@ -67,6 +68,16 @@ function Actor2D:autoMove(dt)
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.ysp = utils.math.toZero(self.ysp, self.yfrc * dt)
end