Ah, right. That's simply because you add the character to the world with this:
Code: Select all
world:add(player,player.x+1,player.y+1,player.width-2,player.height-2)
But then you move the character with this:
Code: Select all
local goalX = player.x + (player.speed*player.xdir*dt)
local goalY = player.y + (player.speed*player.ydir*dt)
local actualX, actualY, cols, len = world:move(player, goalX, goalY, playerFilter)
player.x, player.y = actualX , actualY
You add the player object to the bump world with an offset, but you don't update the object with an offset; you assume its top-left position to equal to player.xy.
As such, you wind up having the player's X and Y positions in the bump world always match the value in the player table. If you want to account for the offset, you will need to keep doing the following:
Code: Select all
local goalX = player.x + (player.speed*player.xdir*dt) + 1 -- add the offset to the goal positions
local goalY = player.y + (player.speed*player.ydir*dt) + 1
local actualX, actualY, cols, len = world:move(player, goalX, goalY, playerFilter)
player.x, player.y = actualX - 1, actualY - 1 -- deduct the offset from the actual positions
So in short, you need to keep in mind how you want to sync up the representation of your character. There can be two approaches:
1) Your player table is a 1:1 representation of the bump world representation (player.xy equaling where the collision box's top-left is in the bump world), and then you apply offsets to how you render your character.
2) Your player table is more of a representation of the rendering positions of your objects (player.xy equaling where the visual top-left might be), and then you apply any desired offsets to the bump world objects when updating them.
Your usage of world:move was assuming approach 1, when you were trying to do 2, essentially.