i am working on a 3rd person style game, i am wanting to know if there is a way of switching between 3rd person and 1st person?
you can have multiple cameras in your scene, you could make 1 camera follow your character in 3rd person mode and put another camera ‘inside’ the character’s head, make sure you don’t render the character in 1st person mode though
then you can switch between the 2 cameras whenever you want
you could also use the same camera and just move it, but i guess this way is a bit more flexible
hi,
how would i switch between the cameras? and also, how would i set the character to not render when in fps mode?
thanks
to activate the other camera:
var anotherCamera : Camera;
anotherCamera.active = true;
to remove the character from the camera just assign the character to a seperate layer and then remove that layer from the camera’s culling mask in the inspector
hi,
ive written the following script(with a lot of help from the forums) but it doesnt seem to work. when i press the stated keys, nothing happens.
does anyone know why?
var camera1 : Camera;
var camera2 : Camera;
function Update () {
if ( Input.GetKeyDown(KeyCode.C))
camera1.camera.enabled = true;
camera2.camera.enabled = false;
if ( Input.GetKeyDown(KeyCode.V))
camera1.camera.enabled = false;
camera2.camera.enabled = true;
}
I haven’t testes but maybe this was what you intended
var camera1 : Camera;
var camera2 : Camera;
function Update ()
{
if ( Input.GetKeyDown(KeyCode.C))
{
camera1.camera.enabled = true;
camera2.camera.enabled = false;
}
else if ( Input.GetKeyDown(KeyCode.V))
{
camera1.camera.enabled = false;
camera2.camera.enabled = true;
}
}
You forgot the curly brackets around the if-blocks, it should be:
var camera1 : Camera;
var camera2 : Camera;
function Update () {
if ( Input.GetKeyDown(KeyCode.C)) {
camera1.camera.enabled = true;
camera2.camera.enabled = false;
}
if ( Input.GetKeyDown(KeyCode.V)) {
camera1.camera.enabled = false;
camera2.camera.enabled = true;
}
}
If the cameras are linked to the script properly, this should do the trick. By the way, the 3rd person platformer tutorial on the unity website covers multiple cameras if I recall correctly; you might want to have a look at that.
I have a question that sort of relates to this… I have the camera switching working, but how do you get the game to be able to switch to a different character controller and back?
For instance, I have a vehicle that I want to be able to get inside. The vehicle has its own character controller and camera, so i want it when you press the e key, it switches to the vehicle camera and controller.
you can enable/disable scripts, just like you do with cameras.
so just use
CharacterControllerScript1.enabled = false;
CharacterControllerScript2.enabled = true;
how would i call the script variable for the character controller swap?