Advice about "Camera Zone".

Started by
3 comments, last by Kryzon 10 years, 2 months ago

Hello.

In this game engine i am working on, i have a camera problem that i will explain in a moment.

Before i continue thought, i must state that i aleredy have a few idea on how to resolve it, but i feel all of them are "awkward". So i come here to hear about yours opinions.

The problem is kind of hard to explain, i will try my best to be as precise as possible.

I have a 2D sidescroller game. In this game is a Camera Class that can move around dynamically, that means it will try it best to keep up with whatever it's bound to.

The camera follow a simple rules: Don't go out of the Level. This mean in a 100x100 Map, the camera won't go left of tile 0 or right of tile 100.

With this come 2 major problem

1. If i wants to make a "secret" area where i do not wants the camera to enter before the player do.

2. If i wants to stop the camera right at the floor level, even if the level go below the floor eventually.

if i am not clear enought, i have attached an image to show the problem.

In picture one, you can see the level Editor. I made a corridor leading to a pit. Picture 2 is zoomed it with the player spawned. You can see in picture 2 the problem. I wants the camera to stop at the floor and not go under the floor until the actor is nearby the pit.

So i got somes idea on how to solve it, but like i said earlier, neither are spectacular.

1. Flag somes tiles as "Don't go in here yet". If the camera is about to show them, stop the movement.

2. In the map header, tell the camera where it can go and where it can't go.

3. Disallow the camera to enter "empty space" or tile flagged as "secret space" (a trigger would unflag such area as soon as the player touch it).

4. Put trigger everywhere in the level to tell how the camera should behave.

Personnaly i would go with option 3 but i wants to hear what everyone is thinking. Maybe there is a better solution i am not thinking of.

Ps: Graphics are just placeholder.

Advertisement

You can try covering your secret area with "secret area tiles" that looks the same as its surroundings. When the player walks into these tiles, they fade / disappear. That way your camera can show the secret area without letting the player know that it's a secret area. Think of the illusion walls in Dark Souls or the breakable walls in Castlevania.

Whenever the player moves, check if the camera needs to move. Clip the motion of the camera against any "void zones." If the player gets very close to an edge of the camera viewport then don't clip the camera against any "soft void zones" in that direction. If the player passes an edge of the camera viewport then don't clip against any "void zone" in that direction.

This means that if a player falls a long way down, the camera works as normal, following the player and keeping it roughly in the middle of the screen (depending on how much "slop" you want when the camera follows the player). When landing on the ground (with a "void zone" below), the camera will now cease to move down and the player will no longer be in the center of the screen. If the player then drops down through the floor somehow, as the player gets near the edge of the screen the camera will begin following the player again.

Depending on level design the margin of the camera viewport which triggers the "void zone" cancellation may need to be particularly small (possibly even less than the size of the player itself).

You could do this with a force-like system as well where each "void zone" exerts a force pushing the camera away from it if close and the player has a spring-like force to try to keep the camera centered on it. Once the spring-like force of the player surpasses the force of any intersecting void zones, disable the void zone entirely until it is no longer intersecting. Another nice effect of using a spring-like force on the player is that the camera will accelerate towards the player and then slow down as it approaches.

This force-based approach can be a nice effect for some games when you have the camera and player disjoint for a moment, like say after the player teleports. If the camera can rescale to keep multiple focal-points within the viewport this can also provide a smooth effect when an item toggles being of interest or not; for instance, if you spawn into a level and want the goal to be visible momentarily you could toggle it on as a point of interest (and the camera "physics" would accelerate to encompass both player and goal and anything in between) and then turn that off after a few seconds (so the camera returns to its normal proportions). Downsides of this approach are that the camera may feel laggy or spongy if it's not tuned just right and it may still end up being inappropriate for certain kinds of games.

Sean Middleditch – Game Systems Engineer – Join my team!

Thanks! I had aleredy implemented the spring-like feature you wrote about. With what you said in mind, i'll just tweak it to stop before clipping with a void, but if the player goes out of focus, the camera will ignore the void flag.

I like this as i don't need to tweak too much.

Another solution is implementing a camera rail: a collection of connected splines that describe the points that the camera can move to.
You will need to program a simple solver algorithm that computes the best camera position on the splines so that the camera best focuses the player.

This way you can build the splines in a way that the camera never reveals certain parts of the level because it can't go there.

This topic is closed to new replies.

Advertisement