function to improve entities moving on collisions and fixed accordingly
made math.round() changed vector() and fixed accordingly
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user