chore: put automove in physics mixin

Fixes #54
This commit is contained in:
Kazhnuz 2020-11-26 21:08:29 +01:00
parent dcc2965431
commit c3ee812d1a
3 changed files with 24 additions and 36 deletions

View file

@ -61,21 +61,10 @@ end
-- PHYSICS FUNCTIONS -- PHYSICS FUNCTIONS
-- Handle movement and collisions. -- Handle movement and collisions.
function Actor2D:autoMove(dt) function Actor2D:moveToFuturePosition(dt)
self:updateHitboxes()
self.onGround = false
self:applyGravity(dt)
local dx, dy = self:getFuturePosition(dt) local dx, dy = self:getFuturePosition(dt)
local newx, newy, cols, colNumber = self:move(dx, dy) local _, _, cols, colNumber = self:move(dx, dy)
return cols, colNumber
-- 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:solveAllCollisions(cols)
self:applyFriction(dt)
end end
function Actor2D:changeSpeedToCollisionNormal(normal) function Actor2D:changeSpeedToCollisionNormal(normal)

View file

@ -71,21 +71,10 @@ end
-- PHYSICS FUNCTIONS -- PHYSICS FUNCTIONS
-- Handle movement and collisions. -- Handle movement and collisions.
function Actor3D:autoMove(dt) function Actor3D:moveToFuturePosition(dt)
self:updateHitboxes()
self.onGround = false
self:applyGravity(dt)
local dx, dy, dz = self:getFuturePosition(dt) local dx, dy, dz = self:getFuturePosition(dt)
local newx, newy, newz, cols, colNumber = self:move(dx, dy, dz) local _, _, _, cols, colNumber = self:move(dx, dy, dz)
return cols, colNumber
-- 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:solveAllCollisions(cols)
self:applyFriction(dt)
end end
function Actor3D:changeSpeedToCollisionNormal(normal) function Actor3D:changeSpeedToCollisionNormal(normal)

View file

@ -127,9 +127,19 @@ function PhysicalActor:checkGround()
end end
function PhysicalActor:autoMove(dt) function PhysicalActor:autoMove(dt)
-- The base actor don't have coordinate self:updateHitboxes()
-- so the autoMove is only usefull to its self.onGround = false
-- 2D and 3D childrens self:applyGravity(dt)
local cols, colNumber = self:moveToFuturePosition(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:solveAllCollisions(cols)
self:applyFriction(dt)
end end
-- HITBOX FUNCTIONS -- HITBOX FUNCTIONS