Code: Select all
function smbxplus.onLoop()
for INDEX,PLAYER in pairs(Player.get()) do
--PLAYER 1
local hitbox = colliders.getAABB(PLAYER) --Load P1's hitbox
--Create a 8 px thick collision sensor on each side of the PLAYER
PlayerHitbox[INDEX] = {
top = colliders.Box(PLAYER.x, PLAYER.y - 8, hitbox.width, 8),
left = colliders.Box(PLAYER.x - 8, PLAYER.y, 8, hitbox.height),
right = colliders.Box(PLAYER.x + hitbox.width, PLAYER.y, 8, hitbox.height),
bottom = colliders.Box(PLAYER.x, PLAYER.y + hitbox.height, hitbox.width, 8),
innerTop = colliders.Box(PLAYER.x + 8, PLAYER.y + 8, 8, 8),
innerBottom = colliders.Box(PLAYER.x + 8, PLAYER.y + hitbox.height - 16, 8, 8)
}
if smbxplus.debug then
PlayerHitbox[INDEX].top:Draw(0xff000099)
PlayerHitbox[INDEX].left:Draw(0x00ff0099)
PlayerHitbox[INDEX].right:Draw(0x0000ff99)
PlayerHitbox[INDEX].bottom:Draw(0xffff0099)
PlayerHitbox[INDEX].innerTop:Draw(0x44444499)
PlayerHitbox[INDEX].innerBottom:Draw(0xffffff99)
end
...
end
...
end
The "..." represents parts of the code I removed because they don't need checked.
Another problem, which makes collision detection imprecise, is that in single player (and two player once I can get it fixed), the position of the hitboxes is slightly out of sync with the player's position when he is moving, so that the player will hit a block slightly before the custom hitbox does.