Search Unity

Overhead camera?

Discussion in 'Scripting' started by Shlimazel, Apr 29, 2008.

  1. Shlimazel

    Shlimazel

    Joined:
    Nov 2, 2007
    Posts:
    42
    I would like to make a camera that would change its position to match the position of a target object, but not rotate with the target object. If you have ever played any of the games of the Escape Velocity series of videogames for Mac, you will know what I mean.

    http://en.wikipedia.org/wiki/Image:Battle2.jpg

    The above link illustrates what I mean. The camera is focused on the ship on the middle.

    I am not sure what would be the best way to do this; could I use a script or is there a way to use a joint to do this?
     
  2. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    Do you want the camera to be precisely centred on the target or shall you only be able to see it and then move to it when you can't see it.
     
  3. Shlimazel

    Shlimazel

    Joined:
    Nov 2, 2007
    Posts:
    42
    I want the camera to remain centered on the target and move with the target object, but not rotate when the target rotates.
     
  4. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    Try this


    Code (csharp):
    1. var target : GameObject;
    2. var height_over = 10;
    3. function Update () {
    4.     pos = target.transform.position;
    5.     pos.y += height_over;
    6.     transform.position = pos;
    7. }
     
  5. Shlimazel

    Shlimazel

    Joined:
    Nov 2, 2007
    Posts:
    42
    That works perfectly! Thank you very much!
     
  6. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    No problem :D