I have some Jelly characters moving togheter on a grid, like miniatures on a game board. Since the board is very large and every Jelly is an human player, they must be all visible on the screen. So, I need the camera to zoom in and out, and follow smoothly the Jellies to watch the entre area covered by the players.
How can I do that? I am really clueless on this.
asked Sep 16 '10 at 08:37 PM
To get you started, you should be able to use some straight forward Vector3 calculations to find a center point between all of the players' positions.
From there you should make that Vector3 the target of your camera so it follows/centers on it. To tackle the zoom, since you should know all the players positions already, you could find the 2 who are farthest apart from each other and use that when calculating where your camera should be on the Y axis.
In response to your comment...
You could use the Mesh class to create a mesh that uses all of the player's transform.position Vector3's as it's vertices.
From there, you can use the Mesh.bounds property to return an Axis Aligned Bounding Box (AABB) which you can use the Bounds.center property (a Vector3) as the focal point of your camera. Then, because you have an AABB, the larger the number, the further out your camera should be, and vice-versa.
Here's a little something to get you started:
Hope that helps.