Search Unity

Look At Camera and maintain Z angle

Discussion in 'Scripting' started by ktest112233, Jun 6, 2019.

  1. ktest112233

    ktest112233

    Joined:
    Jan 7, 2019
    Posts:
    37
    Hi,

    I want a gameObject to Look at camera but at the same time also maintain it's Z angle. Is it possible to do so?

    If I use simple LookAt, the gameobject will face the camera but not maintain its Z angle. Any help related to that would be great. Thank you!
     
  2. DonLoquacious

    DonLoquacious

    Joined:
    Feb 24, 2013
    Posts:
    1,667
    Transform.LookAt has an overload method that takes a Vector3 for the "up direction"- is this insufficient? If you need to lock another axis, you can also use the rigidbody.constraints setting so that the rotation angle is locked while doing the LookAt function, assuming you have a rigidbody on the object.