Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. We're excited to be bringing you the newest Unity features, news, demos, and we've even got some special guests from some of the industry’s most storied franchises. Set a reminder to tune in on YouTube here
    Dismiss Notice
  3. Unity 2018.3 is now released.
    Dismiss Notice

Free look - Reset pos behind player with simple world up

Discussion in 'Cinemachine' started by mrCharli3, Dec 30, 2018.

  1. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    336
    Is there any way to set the camera position behind the player via script? i.e reset it. Currently when my player respawns it's a bit annoying to rotate the camera every time.
    It has to be "Simple world up"

    Thanks!
     
    Last edited: Dec 30, 2018
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    2,130
    Deactivate the vcam game object, place it where you want it, then reactivate it.
     
  3. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    336
    Okay. The thing is I'm not sure which values to modify.
    I would assume its the X axis value, but that one always stays at 0 even when Im moving the camera. Only the Y axis value changes.
    And I can't set it using transform (world) position because that changes all the time.

    I should add that the camera both follows and looks at the player at all times.
     
    Last edited: Dec 30, 2018
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    2,130
    I thought that you want to position it when the player respawns. Is that true?
    In SimpleFollow, the X axis stays at 0. Put the Y axis at 0.5 to place it on the middle orbit.
    Position the vcam's transform to be on the middle orbit, behind the player, i.e. playerPos - (player.forward * orbitRadius) + (orbitHeight * Vector3.up)
     
  5. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    336
    Thanks man,

    I did my best to translate that into code, and setting the Yaxis value works fine, but cannot seem to effect the actual transform:

    Code (CSharp):
    1.  
    2.             public CinemachineFreeLook vcam;
    3.             vcam.m_YAxis.Value = 0.5f;
    4.  
    5.             Vector3 playerPos = ActivePlayer.gameObject.transform.position;
    6.             Vector3 playerForward = ActivePlayer.gameObject.transform.forward;
    7.             vcam.VirtualCameraGameObject.transform.position = playerPos - (playerForward * vcam.m_Orbits[1].m_Radius) + (vcam.m_Orbits[1].m_Height * Vector3.up);
    Tried a few different ways but can't seem to effect the vCams transform at all.
    Maybe I'm misunderstanding you because I can't move the transform of the camera through the editor either.
     
    Last edited: Jan 1, 2019
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    2,130
    You can only alter the vcam's transform while the vcam is disabled, otherwise it will overwrite whatever you do. Disable it, set its transform, then re-enable it.
     
    mrCharli3 likes this.