What if you make them solid, will they properly push other objects?
Yes. Objects intersecting with them when they are moved out will get "pushed outwards" on their collision resolution phase (provided that the "pushers" get moved before the "pushed").
However, this kind of "pushing" is not tunneling-invulnerable. This is, a small-enough platform, moving fast enough, pushing a small-enough object, can end up "traversing" the object or pushing it in the wrong direction.
The way to fix this is to implement a "push" method in the pushed objects, and invoke it on the pushers, with the appropiate dx and dy (which is calculated like this: velocity*(1-col.ti)*dt:
Here's the code for the Platforms / Pushers
Code: Select all
local filter = function(other)
if other.pushable then return 'cross' end
end
function Pusher:update(dt)
local actualX, actualY, cols, len = self.move(self.x + self.vx * dt, self.y + self.vx * dt, filter)
self.x, self.y = actualX, actualY
local col, ti, dx, dy
for i=1,len do
col = cols[i]
dx = self.vx * (1 - col.ti) * dt
dy = self.vy * (1 - col.ti) * dt
col.other:push(dx, dy)
end
end
Here's the code for the "Pushable" items (i.e. the player)
Code: Select all
function Pushable:push(dx,dy)
local actualX, actualY, cols, len = self.move(self.x + dx, self.y + dy, filter)
self.x, self.y = actualX, actualY
-- do something with cols, if needed
end
That would make platforms move things around taking tunelling into account.
Now that I have answered your question, I have another one: I am considering adding the "item" itself to the filter parameters,
as Doctory requested. and I am pondering wether it would be more useful to put it as the first (filter(item, other)) or the last param (filter(other, item)).
- Putting item first feels more "the Lua way", since "self" comes first. You could define 'filter' as a class method and it would work. But it breaks backwards-compatibility.
- Putting it last would be totally compatible with what we have now, but we lose the possibility of defining filter as a method, and it's a bit less idiomatic
Since you seem to be my most advanced (or at least vocal
) user of bump, which option would you prefer? I'm currently leaning towards putting it first, even if it breaks compatibility a bit (we gain some things and it's just a matter of replacing (other) by (item, other) )