Search Unity

Space ship pitch camera help

Discussion in 'Scripting' started by SCMcArthur, Apr 20, 2015.

  1. SCMcArthur

    SCMcArthur

    Joined:
    Feb 24, 2014
    Posts:
    5
    Hello,

    I am working on a camera, which is set to follow the players space ship. I want to camera to have the same rotation as the ships X axis, but I want it's rotation along the Z axis to have a delay. This is what I have so far, but I can't figure out how to make the Lerp happen only on the Z axis.

    Vector3 velocity = Vector3.zero;
    Vector3 forward = playerShip.transform.forward*-cameraOffset.z;
    Vector3 up = playerShip.transform.up*cameraOffset.y;
    Vector3 needPos = (playerShip.transform.position + forward) + up;
    Quaternion needRot = playerShip.transform.rotation;

    transform.position = needPos;
    transform.rotation = Quaternion.Lerp(transform.rotation,needRot,4f * Time.deltaTime);