Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

Switching cameras based on a collider/trigger

Discussion in 'Scripting' started by andyH, Mar 12, 2010.

  1. andyH

    andyH

    Joined:
    Mar 2, 2010
    Posts:
    31
    Hi all, I am hoping someone can give me some insight on how to do the following.

    I am making a lunar lander clone as a project to help me learn unity/jscript, and I want to do the following.

    As my ship gets close to another object, I want to switch view from the main cam to a camera that zooms in closer to the ship, much like the original game did.

    The ship has two coliders, one mesh for physics, and I added a second spherical collider, set it as triger and scaled it up so it should act like a proximity detector that would switch to the zoomed in ship-cam when the ship gets close to anything. I also want to swich back to the main cam once the ship is out of range or rather the second collider isnt colliding with anything.

    I think that the OnTriggerEnter command is needed but have no clue how to use it and make the camera switch. Also any insight on how to tie the ship cam to the ship and make the cam follow the ship in y,z at a fixed distance and ignor the ship rotation (it only rotates around x) would also be very helpful

    many thanks for any assistance.
     
  2. hai_ok

    hai_ok

    Joined:
    Jun 20, 2007
    Posts:
    193
    I have been using this:
    Code (csharp):
    1. camera.depth = Camera.main.depth = x;
    but it doesn't work consistently.

    the idea behind it is that cameras with higher numbers are rendered in front of cameras with lower numbers.