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

@@ -36,20 +36,30 @@ function Arrow:drawBackground()
end
function Arrow:doPhysics()
if not self:isCollidingAt(self.pos.x + self.vel.x, self.pos.y, LoadedObjects.Collisions) then
self.pos.x = self.pos.x + self.vel.x
else
self.stuck = true
end
if not self:isCollidingAt(self.pos.x, self.pos.y + self.vel.y, LoadedObjects.Collisions) then
self.pos.y = self.pos.y + self.vel.y
else
self.stuck = true
-- horizontal collision
self:moveX(
self.vel.x,
function()
self.stuck = true
end
)
if not self.stuck then
-- vertical collision
self:moveY(
self.vel.y,
function()
self.stuck = true
end
)
end
if self.stuck then
self.pos.x = self.pos.x + self.vel.x * (2/3)
self.pos.y = self.pos.y + self.vel.y * (2/3)
self.vel.x = 0
self.vel.y = 0
end
self:adjustLight()
end