x


switching cameras

hello. I am currently working on a 3rd person shooter game, and I have come into a problem. I can't seem to figure out how to make the cameras switch from one another depending on the position of the character.

example: you character is walking down a hallway, and there is a fixed camera. when you turn a corner, it automatically switches to another camera to give you a view of your character after the turn.

If anyone could help with this it would be much appreciated. I have almost no scripting knowledge, so the little bits of help I could find here did little good because I had no idea what to do with the scripts.

more ▼

asked Jul 03 '10 at 06:09 AM

Dbag gravatar image

Dbag
11 3 3 4

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Set up a bunch of triggers in the world (i.e. make a bunch of box colliders or whatever and check this "is trigger" sketch on them).

Put something similar to this on those game objects (untested and I don't use javascript so it probably doesn't even compile):

var switchToCamera : Camera;

function Awake()
{
    switchToCamera.enabled = false;
}

function OnTriggerEnter( var collision :  Collision )
{
    if( collision.gameObject.tag == "Player" )
    {
         switchToCamera.enabled = true;
    }
}

function OnTriggerExit( var collision : Collision )
{
    if( collision.gameObject.tag == "Player" )
    {
         switchToCamera.enabled = false;
    }
}

Basically you need to set up your world where you have a bunch of disabled cameras, and when you enter a zone it turns on the camera for that zone.

There's a little bit more to it than that, like maybe having a default fallback camera that's above the player or something. Or turning off the main camera when you enter a zone (probably just by setting Camera.main.enabled = false; and re-enabled on leave).

more ▼

answered Jul 03 '10 at 06:38 AM

Tetrad gravatar image

Tetrad
7.3k 27 37 89

ok, question: how do you disable cameras? I couldn't figure that out either. every time I add a new camera it starts off with that one.

Jul 03 '10 at 05:45 PM Dbag

The same way you disable any other game object.

Jul 03 '10 at 06:57 PM Tetrad

ok, how do you do that? I am very new to this

Jul 05 '10 at 10:22 PM Dbag

Get a reference to it somehow and set its enabled flag to false.

Jul 06 '10 at 12:27 AM Tetrad

ok. how do I get a reference, what is a flag, and how do I enable it to false? this all sounds like gibberish to me

Jul 07 '10 at 07:53 PM Dbag
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x21

asked: Jul 03 '10 at 06:09 AM

Seen: 597 times

Last Updated: Jul 03 '10 at 06:09 AM