Page 1 of 1
Camera movement.
Posted: Thu Feb 09, 2012 5:22 am
by baconhawka7x
I know that people might not appreciate this post because there's no ".love" or good example. But I was wondering if anyone had any good tips for camera movement. I want a smooth camera, that follows the player.
If anyone has any good techniques for smooth camera movement I'd really appreciate it!;)
Re: Camera movement.
Posted: Thu Feb 09, 2012 5:31 am
by tentus
Make a camera object that gets updated each frame. The camera has an x and y position that gets updated to stay within a certain distance from the player. You can create smoothness by making the camera motion dependent on the difference between the camera position and the player position.
Re: Camera movement.
Posted: Thu Feb 09, 2012 5:56 am
by Taehl
Use
love.graphics.translate for the camera positioning itself. For a smooth tracking behavior, I usually use something like:
Code: Select all
cam.x = cam.x - (cam.x-pc.x) * math.min(dt*2, 1)
cam.y = cam.y - (cam.y-pc.y) * math.min(dt*2, 1)
Don't forget to implement a system to prevent your game from drawing things which are off the screen!
Re: Camera movement.
Posted: Thu Feb 09, 2012 9:12 am
by Ellohir
Re: Camera movement.
Posted: Thu Feb 09, 2012 9:50 am
by coffee
Taehl wrote:Use
love.graphics.translate for the camera positioning itself. For a smooth tracking behavior, I usually use something like:
Code: Select all
cam.x = cam.x - (cam.x-pc.x) * math.min(dt*2, 1)
cam.y = cam.y - (cam.y-pc.y) * math.min(dt*2, 1)
Don't forget to implement a system to prevent your game from drawing things which are off the screen!
Sorry baconhawka7x for mess with your thread. Not good at camera stuff so I want ask Taehl what's the importance of dt in this piece of code. If I'm not wrong you are trying to add some smooth steps to camera right? I would think dt or any time variables not stable enough to be added to any x/y coordinates. So what I missing here? Why instead of give a very small fixed/constant number give a timed inconstant variable?
Re: Camera movement.
Posted: Thu Feb 09, 2012 2:32 pm
by tentus
dt is the time passed since the last frame in the real world. If he wants a smooth motion in the real world, he needs dt. If he just wants a conceptually smooth motion, only in the digital world, he could ignore it.
The point is, dt will make it smooth in relation to the programs performance. Program do NOT run perfectly smoothly, so you need dt.
Re: Camera movement.
Posted: Thu Feb 09, 2012 2:52 pm
by coffee
tentus wrote:dt is the time passed since the last frame in the real world. If he wants a smooth motion in the real world, he needs dt. If he just wants a conceptually smooth motion, only in the digital world, he could ignore it.
The point is, dt will make it smooth in relation to the programs performance. Program do NOT run perfectly smoothly, so you need dt.
thank you
Re: Camera movement.
Posted: Thu Feb 09, 2012 6:38 pm
by Ellohir
Yeah, framerate-independent movement uses dt, for player, enemies and the camera as well
Re: Camera movement.
Posted: Thu Feb 09, 2012 11:56 pm
by The Burrito
I like to have a dead zone where the camera doesn't pan. For In The Dark it only pans the camera if the player is outside of the center third of the screen (vertically or horizontally) and pans at a rate based on the square root of the distance needed to get the player within the dead zone.
The upside to this is the faster the player is moving the closer to the edge of the screen they will get, and if for example you fling the player super fast the camera will lose sight of the player until they decelerate a bit. I think it gives a much better sense of speed.
Re: Camera movement.
Posted: Fri Feb 10, 2012 11:14 am
by Taehl
Oh, that does sound nice.
Still can't wait for In the Dark, by the way.