Ok I "think" I understand now. You want the camera to follow the player? So not the player rotates but the world around him?
Test this code.. I think it is what you want.
Code: Select all
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