Search Unity

Question CinemachineFreeLook How do I accurately set the X axis Angle of the main camera

Discussion in 'Cinemachine' started by DaMaFeng, Dec 28, 2021.

  1. DaMaFeng

    DaMaFeng

    Joined:
    Jun 8, 2020
    Posts:
    9
    I want to know how to accurately calculate the Angle of camera X Axis according to the value of Y Axis
    upload_2021-12-28_18-24-50.png
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    It is a complex algorithm with dependencies on the FreeLook rig settings. There is no simple way to reverse-engineer this. What is the effect you're trying to achieve? Maybe there is a simple alternative.
     
  3. DaMaFeng

    DaMaFeng

    Joined:
    Jun 8, 2020
    Posts:
    9
    I want to enter X and Y values in the input box to rotate the camera to the specified Angle. Now the Y axis rotation of the main camera is the same as that of the virtual camera. I don't know how to get the X axis value. I don't know if I'm making myself clear. Thank you.
    upload_2022-1-12_23-58-45.png
    upload_2022-1-13_0-3-8.png
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Is this something you want to do in the Editor as part of authoring a scene, or is it something you expect to be able to do at runtime?
     
  5. DaMaFeng

    DaMaFeng

    Joined:
    Jun 8, 2020
    Posts:
    9
    I want to use it at run time, either to view objects freely or from a fixed Angle.
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    It would be nice to have a little more context. Do you really need to use the FreeLook, for example? Would a spherical orbit suffice (instead of the FreeLook's complex 3-rig structure)? If you're just setting up spherical orbits, then you can move away from the FreeLook and choosing angles would be easier.
     
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    You can try calling FreeLook.ForceCameraPosition(pos, rot). You give it the desired camera position and rotation. The camera will be placed there, and the X and Y axes get automatically set to the values that will bring the camera as close as possible to the desired pos/rot (the camera is constrained to its orbit settings). The camera will be initially positioned at the input pos/rot, then it will move to the nearest point on its orbit, either slowly or quickly, depending on the damping settings.
     
  8. DaMaFeng

    DaMaFeng

    Joined:
    Jun 8, 2020
    Posts:
    9
    Yes, I only use a few of these features, and I'm trying to find another solution instead of using FreeLook.
     
  9. DaMaFeng

    DaMaFeng

    Joined:
    Jun 8, 2020
    Posts:
    9
    I tried this method, and since I set Follow and Look At, it only changed the position and rotation of the FreeLook, but the view Angle of the main camera did not change.
     
  10. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Instead of FreeLook, you can use a normal vcam with Body = FramingTransposer and Aim=POV. Then the X and Y axes of the POV will correspond nicely with the camera rotation.
     
  11. DaMaFeng

    DaMaFeng

    Joined:
    Jun 8, 2020
    Posts:
    9
    Yes, this is a good method, I can set the camera's X and Y axis rotation very well, thank you.
     
    Gregoryl likes this.