Page 1 of 1

Rotation offset for bodies? (windfield)

Posted: Mon Jan 20, 2025 3:25 pm
by TheJayDizzle
Hi together, I am fairly new to LUA and löve2d.
I am learning everything while creating an autoshooter game. I was about to add new weapons, like a spinning saw that rotates around the player (right now with an axe placeholder sprite). I managed to get the rotating sprite working, but the I don't know how to get it working with the colission body for it. Currently it's just at player's x and y rotating in the correct speed and angle as it seems, but I need to set an offset like for the sprite.

I am still using windfield (haven't gotten the time to really learn box2d, since I want to focus on learning all the other aspects, while windfield is still working).

These are the code blocks for spawning the "saw", setting it's movement and later drawing it:

Code: Select all

function spawnSaw()
    local saw = {}
        saw.x, saw.y = player.x+9, player.y+ 9
        saw.hp = projectiles.saws.hp
        saw.collider = world:newBSGRectangleCollider(saw.x, saw.y, 16,16, 15)
        saw.collider:setFixedRotation(true)
        saw.collider:setCollisionClass('saw')
        saw.angle = 0
        saw.vx = 0
        saw.vy = 0
    table.insert(projectiles.saws, saw)
end

Code: Select all

function handleSawMovement()
    for i,a in ipairs(projectiles.saws) do
        local vx, vy = a.vx,a.vy
        a.angle = love.timer.getTime() * math.pi
        a.collider:setAngle(a.angle)
        a.collider:setLinearVelocity(vx, vy)
        a.x = a.collider:getX()
        a.y = a.collider:getY()
    end
end

Code: Select all

function drawSaw()
    for _, saw in ipairs(projectiles.saws) do
        love.graphics.draw(sprites.saw, player.x, player.y+sprites.axe:getHeight()/2, saw.angle,nil,nil,100,100)
    end
end