Player Hitboxes Acting Strange
Posted: 30 Jan 2016, 4:01
I have this script that creates some custom hitboxes for each player. For some reason, the position of one is affecting the position of the other. P1 and P2's hitboxes both move when only 1 player is moving, and neither of them are positioned at the same place as the player. The way they appear to move doesn't seem to make any sense. Here is the script that I have. It attempts to make a table of all players and run for each player to reduce file size and make it so I don't have to make 2 copies of the script, one for each player. In single player, it works fine.
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.
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
...
endThe "..." 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.