Code: Select all
function player:collisions(dt)
--solid tile collisions
local nx, ny = self.x + (self.xvel * dt), self.y + (self.yvel * dt)
local finalX, finalY, collisions = wrld:move(self, nx, ny)
if #collisions > 0 then
for i,v in ipairs(collisions) do
if v.other.type == "solid" then
if v.normal.y == -1 then
self.yvel = 0
self.onGround = true
elseif v.normal.y == 1 then
self.yvel = 0
end
if v.normal.x == 1 then
self.walljump = true
self.wallDir = "l"
self.xvel = 0
elseif v.normal.x == -1 then
self.walljump = true
self.wallDir = "r"
self.xvel = 0
end
elseif v.other.type == "finish" then
self.state = "finish"
end
end
-- reset player bool variables
elseif #collisions < 1 then
self.walljump = false
self.onGround = false
end
self.x = finalX
self.y = finalY
end
While this works if the player is moving into a tile, it doesn't work if it's right against it and not moving. This happens purely because of the way bump.lua works, I know. But is there a way that'd basically allow walljumping easier for anyone who hasn't tried it for a day. Don't believe me? Check the .love and try it out.
Should I put in a bounding box that is 1-pixel out of the player and check all tiles for a simple AABB check? Currently, that's my only idea however I'm scared that it'd be too memory intensive.
Any suggestions would help,
- redsled