function to improve entities moving on collisions and fixed accordingly

made math.round()
changed vector() and fixed accordingly
This commit is contained in:
lustlion
2022-03-16 18:50:10 +01:00
parent 4d94cc805d
commit 236e23177d
9 changed files with 189 additions and 113 deletions

View File

@@ -67,6 +67,13 @@ function CursedBook:doLogic()
elseif self.status == 4 then
end
if self.isFlying then
local random_x = math.random(-4, 4)/100
local random_y = math.random(-4, 4)/100
self.vel.x = self.vel.x + random_x
self.vel.y = self.vel.y + random_y
end
end
function CursedBook:handleAnimation()
@@ -101,15 +108,21 @@ function CursedBook:handleAnimation()
end
function CursedBook:doPhysics()
if self.isFlying then
local random_x = math.random(-4, 4)/100
local random_y = math.random(-4, 4)/100
self.vel.x = self.vel.x + random_x
self.vel.y = self.vel.y + random_y
end
-- move
self:moveWithCollision()
-- horizontal collision
self:moveX(
self.vel.x,
function()
self.vel.x = 0
end
)
-- vertical collision
self:moveY(
self.vel.y,
function()
self.vel.y = 0
end
)
-- final position
self:adjustLight()
end