Search Unity

Camera Problem

Discussion in 'Editor & General Support' started by erikges, May 28, 2010.

  1. erikges

    erikges

    Joined:
    May 20, 2010
    Posts:
    13
    Hi all,

    I'm alway fighting with the 3dsMax animation fbx import with Unity, but I'm actually facing a new problem with camera...
    I've try to use the Camera Focus, Scrolling and Attributes from Unity example, but without success. Unfortunately when I clic play button my camera leave the scene and looking anywhere except my target :(
    I don't know why, probably due to my fbx scale import problem :/

    So I try to write a new script for my cam, because due to the use of the plateformerController for my Heros, it's impossible to simple attach a camera to the player... it's a 2D/3D game and in this case the camera is alway changing of Z position when the Heros go right or left...

    I want my camera to follow my heros (Target) in X and Y axes, but never move on the Z axe, who could be Z.++7 for example.

    I've try to write a little java script and my camera follow my player transform. but I would like my camera always in Z -7
    Could someone help me ?? here is the beginning of my script :

    Code (csharp):
    1.    
    2. var target : Transform;
    3.  
    4.  
    5.     function Update() {
    6.        
    7.        GameObject.Find("Main Camera").transform.position = target.position ;
    8.        transform.LookAt (target);
    9.  
    10.     }
    11.  
    Maybe this is a easy code for many of you, but I'm a big noob in code :/

    Thanks for your help.
     
  2. erikges

    erikges

    Joined:
    May 20, 2010
    Posts:
    13
    Nobody for help ? :/
     
  3. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    Can you post the script you were originally using? It's not likely that the object's scaling would stop the camera from looking at it correctly.
     
  4. erikges

    erikges

    Joined:
    May 20, 2010
    Posts:
    13
    Hi Andy unfortunately I didn't find any kind of code corresponding of my project except those of the Unity example.

    In this code for me :
    //I create the variable target and get all her transform infos
    var target : Transform;

    //I use Update to use function every frame
    function Update() {
    //I fond the object mainCamera and apply target transform to camera transform
    GameObject.Find("Main Camera").transform.position = target.position ;
    //finally I ask my camera to lookAt the Target var...
    transform.LookAt (target);
    }

    I have try many thing as Vector3 to use only x and y information from var target but I fail by using this code :/
    I would like my cam always stay on the same Z -7 position and only move in x and Y axe following the target...

    Could you help ?
     
  5. erikges

    erikges

    Joined:
    May 20, 2010
    Posts:
    13
    Could someone help to solve this problem ?? :(
     
  6. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    Try changing the line to:-
    Code (csharp):
    1. Camera.main.transform.position = target.position - Vector3.forward * 7.0;
     
  7. Samantha

    Samantha

    Joined:
    Aug 31, 2005
    Posts:
    609
    It's probably not working because you are setting the position of the camera to be identical to what it's supposed to be looking at. That would be like trying to look inside your own eyeballs!