Search Unity

How To Reset The Cinemachine Virtual Camera Transform Through Script?

Discussion in 'Cinemachine' started by SFlowers, Apr 11, 2019.

  1. SFlowers

    SFlowers

    Joined:
    Apr 11, 2019
    Posts:
    1
    I tried to do something like vCam.GetComponent<Transform>().position = new Vector3(0,0,0);
    but the values keep the same, i also disabled the cinemachine virtual camera script but did not helped me.

    Here is the area where i wanted to reset.

     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    2,845
    Since you don't have a follow target in the vcam, it is possible to set the position. Be aware, however, that as soon as you assign a follow target and thus enable the procedural positioning, the vcam will immediately overwrite whatever position you try to set manually.

    normally, the way to do it is just to say vcam.transform.position = bla.
     
  3. inear_sthlm

    inear_sthlm

    Joined:
    Sep 14, 2015
    Posts:
    4
    Old question, but ran into the same issue so posting my solution if someone else search for one. I have follow target , aim target, follow-orbital-transposer and aim-composer. I needed to reset that camera so a transition back again would be the same start values. I did like this:

    vcam.enabled = false;
    vcam.transform.SetPositionAndRotation(startPosition, startRotation);
    vcam.enabled = true;
     
    KolonelKitten, RGBit and EdwinLyons like this.
  4. HavanaBanana

    HavanaBanana

    Joined:
    Jul 3, 2017
    Posts:
    2
    Hi guys,

    i have the same issue. I cannot reset the rotation of my thirdperson vcam (body: framing transposer; aim: do nothing; this camera is a child of my player-gameobject). I have a bunch of cameras like menu-cam, aim-cam, and death-cam with different values.

    What I simply want to do:

    When a player dies, the deathcam (body: orbital transposer; aim: composer) gets activated by increasing the priority. When the player respawns, the regular thirdperson-vcam needs to be re-activated. And it does by setting priorities to values before. But the thirdperson vcam keeps the rotation of the deathcam. The solution above is not working for me.
    I tried to set the transform of my vcam-gameobject and the vcam itself. i also tried nulling the lookat and follow before resetting the rotation to avoid procedural positioning.

    What am I missing?
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    2,845
    Unparent your cameras from the target game object. Main camera and vcams should be separate game objects, not parented to each other or anything that's moving.