Camera = require "libs/hump/camera"
function love.load()
love.physics.setMeter(32)
World = love.physics.newWorld(0, 0, true)
playerBody = love.physics.newBody(World, x, y, "dynamic")
playerShape = love.physics.newRectangleShape(32, 32)
playerFixture = love.physics.newFixture(self.body, self.shape, 1)
playerFixture:setDensity(1)
playerFixture:setFriction(1)
playerFixture:setRestitution(0)
end
function love.update(dt)
World:update(dt)
cam:rotateTo(playerBody:getAngle())
end
function love.draw()
cam:attach()
love.graphics.polygon("fill", playerBody:getWorldPoints(playerBody:getFixtureList()[1]:getShape():getPoints()))
cam:detach()
end
I don't know what you are trying to achieve but your code seems fine from what I can see. I adjusted the example to be runnable on its own. You can rotate by 1 with the tab key.
I guess this is not what you wanted but what do you expect to behave different?
Camera = require "libs/hump/camera"
cam = Camera(0,0,1,0)
function love.load()
love.physics.setMeter(32)
World = love.physics.newWorld(0, 0, true)
playerBody = love.physics.newBody(World, 0, 0, "dynamic")
playerShape = love.physics.newRectangleShape(32, 32)
playerFixture = love.physics.newFixture(playerBody, playerShape, 1)
playerFixture:setDensity(1)
playerFixture:setFriction(1)
playerFixture:setRestitution(0)
end
function love.update(dt)
World:update(dt)
cam:rotateTo(playerBody:getAngle())
end
function love.draw()
cam:attach()
love.graphics.polygon("fill", playerBody:getWorldPoints(playerBody:getFixtureList()[1]:getShape():getPoints()))
cam:detach()
end
function love.keypressed(key)
if key == "tab" then
playerBody:setAngle(playerBody:getAngle() + 1 )
print(playerBody:getAngle())
end
end
Camera = require "libs/hump/camera"
cam = Camera(0,0,1,0)
function love.load()
love.physics.setMeter(32)
World = love.physics.newWorld(0, 0, true)
boxBody = love.physics.newBody(World, -50, -50, "dynamic")
boxShape = love.physics.newRectangleShape(5, 5)
boxFixture = love.physics.newFixture(boxBody, boxShape, 1)
boxFixture:setDensity(1)
boxFixture:setFriction(1)
boxFixture:setRestitution(0)
playerBody = love.physics.newBody(World, 0, 0, "dynamic")
playerShape = love.physics.newRectangleShape(32, 32)
playerFixture = love.physics.newFixture(playerBody, playerShape, 1)
playerFixture:setDensity(1)
playerFixture:setFriction(1)
playerFixture:setRestitution(0)
end
function love.update(dt)
World:update(dt)
local angle = playerBody:getAngle()
cam:rotateTo(-angle)
end
function love.draw()
cam:attach()
love.graphics.setColor(255, 0, 0, 255)
love.graphics.polygon("fill", playerBody:getWorldPoints(playerBody:getFixtureList()[1]:getShape():getPoints()))
love.graphics.setColor(255, 255, 255, 255)
love.graphics.polygon("fill", boxBody:getWorldPoints(boxBody:getFixtureList()[1]:getShape():getPoints()))
cam:detach()
end
function love.keypressed(key)
if key == "left" then
playerBody:setAngle(playerBody:getAngle() - 0.2 ) -- turn left a bit
end
if key == "right" then
playerBody:setAngle(playerBody:getAngle() + 0.2 ) -- turn right a bit
end
print(playerBody:getAngle())
end