Search Unity

set 2 axis on roation

Discussion in 'Scripting' started by udi1997, Mar 4, 2015.

  1. udi1997

    udi1997

    Joined:
    Feb 1, 2013
    Posts:
    1
    I have a C# code on the camera that makes it follow the player by rotation and position from first and third person view:
    Code (CSharp):
    1.     void LateUpdate () {
    2.         if (thirdPersonView)
    3.         {
    4.             transform.position = Vector3.Lerp(transform.position, camPos1.position, Time.deltaTime * smoothFollow);
    5.             transform.forward = Vector3.Lerp(transform.forward, camPos1.forward, Time.deltaTime * smoothFollow);
    6.         }
    7.         else
    8.         {
    9.             transform.position = camPos2.position;
    10.             transform.forward = camPos2.forward;
    11.         }
    12.     }
    13.  
    14.     void Update() {
    15.         if (Input.GetButtonDown("View"))
    16.             thirdPersonView = !thirdPersonView;
    17.  
    18.         rotationY = Input.GetAxis("Mouse Y");
    19.  
    20.         transform.Rotate(Vector3.right, -rotationY);
    21.     }
    What I am trying to do is make the camera follow the player and when I use the mouse and moves it up and down the camera rotation should move too up and down.
    As you can see I have tried that but this is not working right beacouse of the line:
    Code (CSharp):
    1. transform.forward = camPos2.forward;
    I have tried to split the forward to 3 part: the X Y Z and sets the X to transform.rotation but it is not working too.
    How can I make it work?