How to make smooth camera movement?
Posted: Wed Nov 25, 2020 4:27 pm
Hello, i'm new to love2d and i can't resolve this simple problem, basically i was able to implement a camera that follows the ''player'' ( a simple square) but i don't know how to make the camera more smooth like for example in this video (around 23.20) https://youtu.be/hRsMCMe5K7s?t=1400 I'm using hump for the camera and i read on the documentation (https://hump.readthedocs.io/en/latest/c ... -smoothers) something about smoothness but still can't understand what to do. Any help is appreciated!
Edit: adding this in love.update i kinda get the result that i want but it has some problems
Code: Select all
Camera = require "camera"
function love.load()
player = {}
player.x= 500
player.y= 120
camera = Camera(player.x, player.y)
end
function love.update(dt)
local dx,dy = player.x - camera.x, player.y - camera.y
camera:move(dx/2, dy/2)
--movement control
if love.keyboard.isDown("a") and player.x > 0 then
player.x = player.x - 5
end
if love.keyboard.isDown("d") and player.x < 10000 then
player.x = player.x + 5
end
if love.keyboard.isDown("w") and player.x > 0 then
player.y = player.y - 5
end
if love.keyboard.isDown("s") and player.x < 10000 then
player.y = player.y + 5
end
end
function love.draw()
camera:attach()
--background
love.graphics.rectangle('fill',0,0,500,300)
love.graphics.setColor(11, 0, 12)
--player
love.graphics.rectangle('fill',player.x,player.y,100,100)
love.graphics.setColor(0, 0, 1)
camera:detach()
end
Code: Select all
local dx,dy = player.x - cam.x, player.y - cam.y
if(dx>50 or dy>50 or dx<-50 or dy<-50) then
cam:move(dx/10, dy/10) end