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!;)
Camera movement.
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- baconhawka7x
- Party member
- Posts: 494
- Joined: Mon Nov 21, 2011 7:05 am
- Location: Oregon, USA
- Contact:
- tentus
- Inner party member
- Posts: 1060
- Joined: Sun Oct 31, 2010 7:56 pm
- Location: Appalachia
- Contact:
Re: Camera movement.
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.
Kurosuke needs beta testers
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
Re: Camera movement.
Use love.graphics.translate for the camera positioning itself. For a smooth tracking behavior, I usually use something like:
Don't forget to implement a system to prevent your game from drawing things which are off the screen!
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)
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Re: Camera movement.
And changing mouse coordinates to world coordinates. Here is a nice tutorial for cameras here if you want to take a look:
http://nova-fusion.com/2011/04/19/camer ... he-basics/
http://nova-fusion.com/2011/04/22/camer ... scrolling/
http://nova-fusion.com/2011/05/09/camer ... nt-bounds/
http://nova-fusion.com/2011/04/19/camer ... he-basics/
http://nova-fusion.com/2011/04/22/camer ... scrolling/
http://nova-fusion.com/2011/05/09/camer ... nt-bounds/
Re: Camera movement.
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?Taehl wrote:Use love.graphics.translate for the camera positioning itself. For a smooth tracking behavior, I usually use something like:
Don't forget to implement a system to prevent your game from drawing things which are off the screen!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)
- tentus
- Inner party member
- Posts: 1060
- Joined: Sun Oct 31, 2010 7:56 pm
- Location: Appalachia
- Contact:
Re: Camera movement.
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.
The point is, dt will make it smooth in relation to the programs performance. Program do NOT run perfectly smoothly, so you need dt.
Kurosuke needs beta testers
Re: Camera movement.
thank youtentus 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.
Re: Camera movement.
Yeah, framerate-independent movement uses dt, for player, enemies and the camera as well
- The Burrito
- Party member
- Posts: 153
- Joined: Mon Sep 21, 2009 12:14 am
- Contact:
Re: Camera movement.
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.
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.
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
Re: Camera movement.
Oh, that does sound nice.
Still can't wait for In the Dark, by the way.
Still can't wait for In the Dark, by the way.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Who is online
Users browsing this forum: Bing [Bot], Google [Bot], Majestic-12 [Bot], slime and 7 guests