Well the only thing I can say is that the code seems a bit "involved" - there's lots of indirection - and maybe that's on me because there's certainly a bit of indirection in the bump demo as well. But you are adding lots of extra conditionals that make the code difficult to read, without adding much value. That makes finding bugs like this difficult.To solve it I just let the resolveCollision method return the new x and y position and I use them as newx and newy instead of wx, wy. It works but I hate the way it is done... I would love to hear some better ideas from you guys..
Here's an example:
Code: Select all
if self.collidable then newx, newy = self:processCollisions(newx, newy) end
Code: Select all
function Object:processCollisions(x,y)
return x,y
end
Code: Select all
newx, newy = self:processCollisions(newx, newy)
Code: Select all
if len > 0 then
for i=1, #cols do ...
else
self.onGround = false
end
Code: Select all
self.onGround = len > 0
Code: Select all
local other = cols[i].other
if self.resolveCollision and other.collidable then
self:resolveCollision(other)
end
Code: Select all
self:resolveCollision(cols[i].other)
Code: Select all
Object:processCollisions(goalx, goaly)
local wx, wy, cols, len = self.collisionWorld:move(self, goalx, goaly, self.filter)
self.onGround = self.len > 0
for i=1, #cols do
local rx,ry = self.resolveCollision(cols[i].other)
if rx then return rx, ry end
end
return wx, wy
end
A couple things: first, world:move uses world:update internally, so even if you only use move, you are still using update anyway. Second, what update does is equivalent to removing the object and recreating it. It just optimizes the case in which the object has not moved at all, or has moved so little that it is in the same cell group. So even if what you do works, it's bound to be a bit slower than using update. But whatever floats your boat