If he is going for an isometric platformer, then I would use not use a base variable but rather a z position variable...
Yeah, but I doubt it. Or it is too early too assume now.
Back to topic:
For example, when the character jumps forward to a platform which is higher than the ground. When his x-axis overlaps the platform, his base altitude changes to the height of the platform.
So in love.update, you check like this:
Code: Select all
.....
-- check base
local max_height = 0
for _,p in pairs(platforms) do
if p.ypos<oliver.ypos and oliver.xpos>p.xpos and oliver.xpos<p.xpos+p.width and p.ypos>max_height then
max_height = p.ypos
end
end
oliver.ybase = max_height
if oliver.ypos>oliver.base then --gravity
oliver.yvel = oliver.yvel + g
end
oliver.ypos = oliver.ypos + oliver.yvel
oliver.xpos = oliver.xpos + oliver.xvel
if oliver.ypos<=oliver.base then -- land
oliver.ypos = oliver.base
oliver.yvel = 0
end
I know you can make oliver.ybase local ybase in this example. But I prefer to make it a property just in case I use it elsewhere, for example, another function.
--------
Edit*
And the character probably needs a height property, if you want to do the bump into ceiling logic. But that'll be another story.