LOVE2D's draw function makes it trivial to position sprites this way:
Code: Select all
love.graphics.draw(guns.equipped.sprite, player.x, player.y, player_angle(), 1, 1, guns.equipped.offsX, guns.equipped.offsY)
Using the bump.lua library to handle collisions, here is the closest I got:
Code: Select all
local goalX = b.x + math.cos(b.direction - math.pi/2) * b.speed * dt
local goalY = b.y + math.sin(b.direction - math.pi/2) * b.speed * dt
local actualX, actualY, cols, length = world:move(b, goalX - b.offsX, goalY - b.offsY, bulletFilter)
b.x, b.y = actualX + b.offsX, actualY + b.offsY
Red are the collision boxes, blue-white are the sprites. You can see that this code works fine when the player's angle is exactly up, but fails in all other cases. Intuitively that says I need to be doing some trigonometric transformations to account for the player's angle.
Given that my game is a top-down shooter the concept of local/global coordinates has become more relevant over time and I'd like to gain a better grasp of the math involved. Effectively I want to make whatever calculations are happening under the hood for ox,oy in love.graphics.draw more generic for use across my codebase. Thanks in advance.