One Camera With Multiple Targets

Started by
9 comments, last by Kyall 12 years ago
I'm currently working on a 3D multiplayer game with a singular camera that tracks multiple targets. Right now it translates its position relative to the centroid. This causes issues when, for example, 3 players are in one corner and one player is in the other. Anyone have a relatively simple algorithm that properly weights how these targets contribute to the lookat/position of the camera and ensures no target ever goes off screen?
<shameless blog plug>
A Floating Point
</shameless blog plug>
Advertisement
My first thought is to define a function that, given the coordinates of the targets (after projection), computes a utility (how happy we are with the situation). You can then compute the gradient of this function with respect to the position parameters of the camera, and move the camera in the direction that maximizes the utility.

Does that make sense?

My first thought is to define a function that, given the coordinates of the targets (after projection), computes a utility (how happy we are with the situation). You can then compute the gradient of this function with respect to the position parameters of the camera, and move the camera in the direction that maximizes the utility.

Does that make sense?

That makes sense, but what might the inputs/outputs be for a typical utility function? I get this is the general idea, but finding a way to process that utility function is the tricky part.
<shameless blog plug>
A Floating Point
</shameless blog plug>
You should also zoom in and out to match view size to target position; you are effectively trying to keep inside the view a composite target that, in addition to moving, becomes larger if the tracked characters move apart and smaller, up to the size of a single character, if they move closer to each other. In your example, you have to zoom out to include all "corners" over the course of many frames, as characters spread around.

Given a camera position, I'd compute a satisfactory frustum to frame every tracked target and merge them (leftmost left side, rightmost right side, etc.) to obtain a frustum that includes all targets, which translates easily to a camera transform matrix. Meanwhile, you can move the camera to a better place.

Omae Wa Mou Shindeiru

Your utility function can be a sum of several terms. Make a soft function that rewards being near the center of the screen, and add that for each target. Then add something that rewards having the targets be separated on the screen, perhaps by pairs, or perhaps by the distance between the two most distant targets (in screen space).

You'll have to play around with it until you are happy with the results. If you are not happy with the results, think of what feature of the configuration doesn't make you happy, and tweak the utility function to represent that. Rinse. Repeat.
If you want it simple, you could just average the coordinate positions of all targets that your camera needs to look at, then have your camera focus on the averaged position.

If you want it simple, you could just average the coordinate positions of all targets that your camera needs to look at, then have your camera focus on the averaged position.

We've been doing that but, for example, when 3 are in one corner and 1 is in the other, the isolated target is not in the camera view at all.
<shameless blog plug>
A Floating Point
</shameless blog plug>
We've been doing that but, for example, when 3 are in one corner and 1 is in the other, the isolated target is not in the camera view at all.[/quote]
In some cases, it may be impossible to have every target on screen, unless your camera is reaaaally far away (in which cases the targets might be much too small to be seen).

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”


We've been doing that but, for example, when 3 are in one corner and 1 is in the other, the isolated target is not in the camera view at all.

In some cases, it may be impossible to have every target on screen, unless your camera is reaaaally far away (in which cases the targets might be much too small to be seen).
[/quote]

Perhaps you could transition to two cameras with a split screen in that case. It might work for some games, and it would be really cool if done well.
Have you thought of something like one of the Lego games? I don't recall which one specifically, but Pirates may be what I am thinking of. If you had a second player, and the camera could not zoom out enough, instead of 'locking' the camera in the level to view the 2 players, and having one player 'push' the other one when they move further out of bounds, the screen would split itself diagonally, and if you moved further away from each other, the split would progressively align itself vertically.

I do not know how well it could translate to more than 4 players, maybe some dynamic viewport magic :)

This topic is closed to new replies.

Advertisement