Camera movement.

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
baconhawka7x
Party member
Posts: 491
Joined: Mon Nov 21, 2011 7:05 am
Location: Oregon, USA
Contact:

Camera movement.

Post 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!;)
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Camera movement.

Post 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.
Kurosuke needs beta testers
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: Camera movement.

Post 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!
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+.
User avatar
Ellohir
Party member
Posts: 235
Joined: Sat Oct 22, 2011 11:12 pm

Re: Camera movement.

Post by Ellohir »

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/
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: Camera movement.

Post 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?
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Camera movement.

Post 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.
Kurosuke needs beta testers
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: Camera movement.

Post 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
User avatar
Ellohir
Party member
Posts: 235
Joined: Sat Oct 22, 2011 11:12 pm

Re: Camera movement.

Post by Ellohir »

Yeah, framerate-independent movement uses dt, for player, enemies and the camera as well :nyu:
User avatar
The Burrito
Party member
Posts: 153
Joined: Mon Sep 21, 2009 12:14 am
Contact:

Re: Camera movement.

Post 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.
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: Camera movement.

Post by Taehl »

Oh, that does sound nice.

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+.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 40 guests