First Person Camera switch to Third Person Camera on Object

I have a first person exploration game that i’m working on. I am not to familiar on how to code, but I do generally understand how to read it after going through a few dozen tutorials. My question is, how would I go about walking up to a spaceship whilst in a first person view and hitting a key next to the spaceship to enter the spaceship in a third person view? I would need some script telling my first camera to disappear and the engage my second one, right? I am so confused, please enlighten me! :smiley:

you could do it that way. If you create variables for each camera, you can toggle them like:

var camera1 : Camera;

var camera2 : Camera;

camera1.enabled = false;

camera2.enabled = true;

(normally your primary camera is tagged “Main Camera”, and could be accessed from anywhere with Camera.main, as in: Camera.main.enabled = true; just FYI)

OR, you could simply zoom out and raise up a bit, probably a bit more complex for your position. To zoom out with a perspective camera, you would say:

Camera.main.fieldOfView = Mathf.Lerp(Camera.main.fieldOfView,targetZoom,Time.deltaTime * speed);

(where targetZoom and speed are floats)

EDIT:

to flesh it out a bit

var ship : GameObject;
var player : GameObject;
var getInShipDistance : float = 1;
var camera1 : Camera;
var camera2 : Camera;

function Start()
{
ship = GameObject.FindWithTag("ship");
player = GameObject.FindWithTag("player");
var tempCamera = GameObject.FindWithTag("camera1");
camera1 = tempCamera.GetComponent(Camera);
tempCamera = GameObject.FindWithTag("camera2");
camera2 = tempCamera.GetComponent(Camera);
}

function Update()
{
var distance = Vector3.Distance(ship.transform.position,player.transform.position);

if (distance <= getInShipDistance)
{
camera1.enabled = false;
camera2.enabled = true;
//code to start animation etc for getting in ship
}
}

of course, this script would probably be attached to the player (or one of the other referenced objects), so you could eliminate that variable. For example, if it were attached to the player, you wouldn’t need the player variable. The line for distance would instead simply be:

var distance = Vector3.Distance(ship.transform.position,transform.position);

Alright, thank you so much. I have a feeling this would work, now I just need to figure out how and where to implement this into my game. Do I make a new script and attach it to both of my cameras? Thank you again for helping!