fix(actor3D): fix checkGround not trying the right coordinate

This commit is contained in:
Kazhnuz 2019-06-30 22:04:30 +02:00
parent 30a0d59a41
commit 5f5b4da9c5

View file

@ -102,21 +102,21 @@ end
-- All functions related to gravity
function Actor3D:applyGravity(dt)
self.zsp = self.zsp - (self.grav * dt)
local grav = self.grav * -1
self.zsp = self.zsp + (grav * dt)
if utils.math.sign(self.zsp) == utils.math.sign(self.grav) then
if utils.math.sign(self.zsp) == utils.math.sign(grav) then
self:checkGround( )
end
end
function Actor3D:checkGround()
local dx, dy, dz = self.x, self.y, self.z + utils.math.sign(self.grav)
local dx, dy, dz = self.x, self.y, self.z - utils.math.sign(self.grav)
local newx, newy, newz, cols, colNumber = self:checkCollision(dx, dy, dz)
for i, col in ipairs(cols) do
if (col.type == "touch") or (col.type == "bounce") or (col.type == "slide") then
if not (self.grav == 0) then
if col.normal.z ~= utils.math.sign(self.grav) then self.onGround = true end
if col.normal.z == utils.math.sign(self.grav) then self.onGround = true end
end
end
end