Search Unity

Virtual Camera Axes Reset Upon Transition From Freelook Camera

Discussion in 'Cinemachine' started by westingtyler, Nov 10, 2019.

  1. westingtyler

    westingtyler

    Joined:
    Dec 7, 2013
    Posts:
    34
    I have a 3rd person freelook camera and a 1st person virtual camera that players can press a button and swap between. Everything works great except for one thing:

    Upon transferring back out of the 1st person camera into the 3rd person camera, the 3rd person camera "forgets" the direction it should be facing and resets.

    I need to copy the Y and X axes of the free look cameras, before transitioning to others. I actually solved it MOSTLY (when switching among free look cameras) by using the "inherit position" tick box I never saw before, but the problem remains when transferring away from the 1st person camera (virtual camera) to the 3rd person cameras (free look cameras). when I transition from 1st to 3rd, it seems it TRIES to inherit the position but can't find the Y and X axis settings from the 1st person virtual camera, so it defaults to Y=1 and X=90

    I need to somehow get the 1st person Virtual Camera's Aim > POV > Vertical Axis > Value and Horizontal Axis > Value float settings, convert those to correct Y and Z rotation settings, and paste those into the "inherited position" of the 3rd person camera in its Y axis and X axis. I've attached a picture of what I need to do.

    I need to be able to get and set these float properties but cannot figure out how. I can do float remap and convert/normalize them, if I can just figure out how to retrieve and set them. I use playmaker, and they told me to ask you guys here what needs to be done.
     

    Attached Files:

    R0b_g likes this.
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    I suppose what you're trying to do is to push the 1st person camera back along its fwd axis, until it hits the FreeLook orbit, right? So yes, you can get the vcam pos and fwd, and find the appopriate X and Y axis values to set. That's pretty much what the Inherit Position does, only it uses the vcam's Follow target to determine the pushback direction. If the 1stPerson vcam is right on top of the FollowTarget, then it won't be able to grab the direction properly. Do you think that's what's happening?

    If so, maybe you can fix it by putting the POV cam a little behind the follow target. Maybe that means moving the follow target up into the head (is it at the feet now?) and adjusting the offsets in the vcams.

    If that approach doesn't work, then you can try making the calculations you refer to. There's code in CinemachineFreeLook.cs that does something similar (look for OnTransitionFromCamera); you could probably use it as reference. However, there are subtleties involved - I would recommend first trying to move the Follow Target position so that the builtin InheritPosition will work properly.
     
  3. westingtyler

    westingtyler

    Joined:
    Dec 7, 2013
    Posts:
    34
    Thanks. I'm actually not smoothly transitioning the cameras but swapping instantly from one to the other, depending on which scroll wheel direction you press.

    You were correct about the Follow Target. It was right at the same spot as the 1st person virtual camera. I moved the follow target back an inch or two, and now when transitioning out of 1st person into the over the shoulder free look camera view, the horizontal X facing direction is inherited. The Axis Control: Y Rotation (0 to 1) is still not inherited, no matter where I move the follow target.

    Going in reverse order DOES work. If I tilt the camera to look up high while in over the shoulder view, then go into 1st person, the 1st person camera is looking up high. But now when i go back out into the over the shoulder view, the camera Axis control Y axis value defaults to 1 when it SHOULD be somewhere between 0 (looking up high) and 1 (looking at the ground.) So I always am looking at the ground when I go from 1st person to Over the Shoulder.

    I'm not a coder as I use Playmaker to script, so I have been unable to figure out where the script value I need to copy is located. there's a "get property" and a "set property" action, but looking in there, the CInemachine component has like a hundred billion m_Y_axis_normal rotation and Y_axis_rotation when at grandma's house eating cookies.float and Y_axis rotation mainly for Sundays and national holidays" floats, and I've tried to go through and get and set each one to find the Y values I need to no avail.

    I need to somehow get the hidden "Axis Control: Y Rotation" value (ie looking up or straight ahead or down) of the 1st person virtual look camera, and copy that value to the over the shoulder free look camera's "Axis Control: Y axis value". Could you point me in the direction of the name of that variable on the 1st person virtual camera, and what variable it should be copied to, on the Cinemachine free look over the shoulder camera? Moving the follow target gave one of the big pieces, the X value is now inherited, but now I'm only missing that last piece of the Y value to get/set/inherit.
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    FreeLook.m_YAxis.Value

    and
    vcam.GetCinemachineComponent<CinemachinePOV>().m_HorizontalAxis.Value


    Unfortunately I don't know what that looks like in Playmaker.

    However, there might be some good news. New in CM 2.6 (available in preview) is a ThirdPersonFollow camera, which can easily double as a 1st-person camera if you set the offsets to 0 (or whatever puts the camera on the player's nose).

    upload_2020-3-19_9-50-10.png

    The paradigm connecting to the player is a little different from the FreeLook/POV combo you have, and it might mean rethinking a few things for you if you choose to go that route.

    You can look at the new 3rdPersonDeadCenterAim example scene if you want to check it out.
     
    Last edited: Mar 19, 2020
  5. westingtyler

    westingtyler

    Joined:
    Dec 7, 2013
    Posts:
    34
    thanks. I will check it out. Now that you've confirmed those are the values I've needed, I've written back to the playmaker people since I cannot find those variables anywhere in the Get/Set Property actions. I'm also excited to try out the 3rd person follow camera. Now I just need to find out how to additively bake an open world light map in sections and blend between different ones at different times of day, and i'm set.