Search Unity

Moving and Rotating Camera Problems

Discussion in 'Scripting' started by lefantome, Nov 14, 2009.

  1. lefantome

    lefantome

    Joined:
    Nov 14, 2009
    Posts:
    8
    I set up a Camera for my game which is following an empy object with SmoothFollow Script. I move the empty object with fps walker.

    No I want to rotate the camera when I press some keys on keyboard.

    Using transform.Rotate(0,Input.GetKey(...),0);

    or

    transform.rotation. y += Input....

    in the smoothfollow script doesn't work.


    What should I do?

    thanks :D
     
  2. Troy-Dawson

    Troy-Dawson

    Joined:
    Nov 2, 2009
    Posts:
    120
    Instead of rotating the camera' transform directly you should add or use (I don't have the SmoothFollow script here right now) a Vector3 point of interest that the camera is looking at via interpolation and finally Transform's LookAt();

    Use the inputs to modify the point of interest relative to the character, and in the Update() have the camera view vector try to look at the point of interest.

    To help you debug, add a little cube to the scene and update it to the camera's point of interest location.

    Think of how to have things smoothly adjust (preferably in FixedUpdate()) instead of just modifying transforms directly.

    This is tricky but fun.
     
  3. lefantome

    lefantome

    Joined:
    Nov 14, 2009
    Posts:
    8

    how can I modify it? It moves only on x z coordintes