Page 1 of 1

Camera logic to keep level and players within view

Posted: Mon Aug 01, 2016 10:38 am
by zell2002
I'm doing a platformer/beat em up like Smash Brothers, so I want the camera to stay on the characters while they move around.
I want the camera to follow the players and zoom out but have a limit relative to the level. I was thinking in my level editor id add a bounding box that says camera cant move further than these points and then maybe the same for a zoom out point.
I dont know if this the best approach.

Currently my camera code finds the middle point between all players and "Looks at" that point. When the distance between players reaches X the camera starts to pan out. The camera zooms in/out relative to the distance between players, but will eventually reach a max zoom and lock there.

I was wondering if anyone has any pointers/advice on this?

Re: Camera logic to keep level and players within view

Posted: Mon Aug 01, 2016 1:49 pm
by palmettos
I'm personally using Tiled with bump and outlining my maps wherever I don't want the camera to go beyond with a special tile that has an attribute "camera_collide." I put the camera rect in the bump collision world and only process its collisions against tiles with the "camera_collide" attribute. It works pretty well so far.

Re: Camera logic to keep level and players within view

Posted: Mon Aug 01, 2016 10:53 pm
by alloyed
For cameras I strongly suggest skimming this article:

http://www.gamasutra.com/blogs/ItayKere ... ollers.php

It's pretty exhaustive, including even the smash bros. example.