From 049213000ab4a04d3e51ba0aa4bf5f818a083f49 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 27 Jun 2019 21:29:49 +0200 Subject: [PATCH] improvement(world): separate future position and friction from autoMove --- gamecore/modules/world/actors/actor2D.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/gamecore/modules/world/actors/actor2D.lua b/gamecore/modules/world/actors/actor2D.lua index 9c0e9b4..ff218ba 100644 --- a/gamecore/modules/world/actors/actor2D.lua +++ b/gamecore/modules/world/actors/actor2D.lua @@ -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