Search Unity

DizzyCam

Discussion in 'Scripting' started by dacloo, Feb 16, 2006.

  1. dacloo

    dacloo

    Joined:
    Jun 30, 2005
    Posts:
    469
    Hi there,

    I am creating a racetrack with a sphere on it that will be my "car".
    Just an exercise for code stuff.
    I have troubles understanding how I can only rotate my camera
    around an ax I want (e.g when the race track heads left, and I steer left,
    the camera rotates in 1 ax, I dont want the camera to roll like the sphere itself.

    I am looking for the right syntax, e.g in pseudocode:

    Code (csharp):
    1.  
    2. transform.rotate(transform.pitch, transform.yaw, target.roll);
    3.  
    here's the code:

    Code (csharp):
    1.  
    2. var target : Transform;
    3. var distance = 10.0;
    4. var height = 10.0;
    5.  
    6. function LateUpdate () {
    7.   if (!target)
    8.   return;
    9.   // align this camera to the target position
    10.   targetPosition = target.position;
    11.   transform.position = targetPosition;
    12.   transform.position.y += height;
    13.  
    14.   // and now make sure the camera only rotates
    15.   // in the ax we want.
    16.    
    17.   targetRotation = target.rotation;
    18.   // STUFF HERE - What do I do now?
    19.   }
    20.  
    I'll do some "lerping" later on.
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Code (csharp):
    1.  
    2. transform.eulerAngles = Vector3(0, target.eulerAngles.y, 0);
    3.  
     
  3. dacloo

    dacloo

    Joined:
    Jun 30, 2005
    Posts:
    469
    ps:

    I don't understand "perpendicular to worldUp", my English ain't that good!
    Could someone explain this please? Thanks!
     
  4. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    perpendicular means orthogonal.
    Or an angle of 90 degrees between the forward and upVector in this case.
     
  5. dacloo

    dacloo

    Joined:
    Jun 30, 2005
    Posts:
    469
    Thanks a lot Joachim!
    It's still going beserk though :eek:

    But why should I use eulerAngles in this case?
    Why is there a difference between eulerAngles and Quaternions?