- Home /
Zoom out from First Person to Third Person
Hello!
Would it be possible to have a camera zoom out from a first person view to a third person view (smoothly) when you hit a button?
Thanks!
Christian Stewart
Answer by Chapter9 · Apr 30, 2010 at 04:17 PM
Hi,
Here's a quick and dirty Camera Manager...
To create a first person/third person camera, create two empty object called FirstPerson and ThirdPerson and add them as a children of the main character. Position them as they would be a camera. Then add this script to your camera and set the DestinationObject default property to the FirstPerson Object. When you want to switch to the third person, change the CameraInterpolate.DestinationObject variable to the ThirdPerson object.
I recommend you to learn about Unity Interpolation functions, they are quite useful. Making a good 3d game camera is a lot more than that and quite complicated, but this will get you started...
using UnityEngine; using System.Collections;
public class CameraInterpolate : MonoBehaviour {
public GameObject DestinationObject;
public float Speed = 10;
void Update () {
if (DestinationObject)
{
// Interpolate from current position to the destination object position and orientation
Vector3 newposition = Vector3.Lerp(transform.position, DestinationObject.transform.position, Time.deltaTime * Speed);
Quaternion newrotation = Quaternion.Slerp(transform.rotation, DestinationObject.transform.rotation, Time.deltaTime * Speed);
transform.position = newposition;
transform.rotation = newrotation;
}
}
}
Answer by Random Indie · Apr 27, 2010 at 10:52 AM
Check out the 3rd Person Shooter Example.
IIRC the pertinent game objects are the player, AimTarget, MainCamera, and the Third person camera controller script (can't remember it's name exactly but it's attached to the camera).
Using the camera controller script you can set the camera inside your character's head (I think the variable was camOffset). You would then want to add another Vector3 (say thirdPerson Offset) and just slerp or lerp the camera between the two coordinates when a button is pushed.
There's another vector3 called pivot offset in there, you'll want to center that on your object then raise the camOffset above that into the character's head.
If you do it this way, you get built in camera collision (if the camera hits say a wall, it will move toward the player so that they aren't blocked by say a column or a tree) in third person.
Hope that helps!
P.S. You shouldn't be able to see your character when in 1st person mode this way as you'll be looking at the back sides of the polygons therefore they shouldn't render.
Answer by spinaljack · Apr 27, 2010 at 09:23 AM
You can set 2 cameras, one for fps and one for 3rd person, toggle them on and off with a button. When you toggle from fps to 3rd person move the transform of the 3rd person camera to the same world position as the fps cam and then it should pull back by itself (assuming you've set a target distance for the 3rd person camera to be behind the player)