Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Rotating object like camera/other object on scene

Discussion in 'Editor & General Support' started by Nirvan, Jan 29, 2014.

  1. Nirvan

    Nirvan

    Joined:
    Nov 16, 2013
    Posts:
    134
    Hi I have troubles with rotating my object to be rotated like one of other objects.
    I have null object which is pivot point of my other objects, I want this pivot point to be rotated like camera, because pivot from camera position is wrong to my objects.

    I tried with something like:

    transform.rotation = myCam.camera.transform.rotation;

    transform.rotation = myCam.transform.rotation;

    or
    Quaternion rot = gameObject.transform.rotation;
    rot.z = myCam.transform.rotation.z;
    transform.rotation = rot;

    and something with euler angles.

    But all doing it wrong.
    Now it working good when I do something like transform.rotation = target.camera.transform.rotation;
    and put in my pivot point second pivot point but rotated 90 degrees in Y axis.
    Can I do it in code without additional pivot points?