Search Unity

Change angle of cinemachine follow at runtime

Discussion in 'Unite Now' started by ciaran_unity342, Dec 7, 2020.

  1. ciaran_unity342

    ciaran_unity342

    Unity Technologies

    Joined:
    Jun 7, 2018
    Posts:
    2
    I have units in a tactics game, with vcams on gameobjects parented to the base gameobject. These vcams are set, in the prefab, to follow the unit.

    When the game starts up, the vcams all unparent themselves (so they don't rotate with the unit) and continue to follow the units. As the turns end, a script swaps the priority of the vcams so that the unit whose turn it is has the vcam with the highest priority.

    I would like to allow the player to be able to use WASDQR keys to 'take control' of the vcam and move it around freely. This in itself is no problem, however the issue is that should the player change the rotation around the screen (done by a camera parented to a target 'dolly' object), I would like it such that when the turn is over and the game pushes the view to the next unit (and their vcam) it keeps the same follow angle that the player settled on.

    so basically, the player can switch angles and move about the screen, but when the game changes turn, it guides the camera to the next unit, but maintains the angle.

    I've tried parenting the vcam to a dolly on the players, and then having a movement script rotate ALL vcams when the player controlled vcam changes angle, but firstly they seem to all rotate on the spot, not AROUND anything, and secondly, they all snap back to their previous angle once the player let's go of an input button.

    Thanks so much!
     
    astayumi611 likes this.
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    My first thought is to use a single vcam, with a single invisible follow target. The vcams's binding mode is in target's local co-ords, so that when the target rotates, the vcam orbits around it (this assumes that you have a Transposer in the vcam;s Body section. If you have something else, let me know).

    Let your script move the follow target to the new unit at the beginning of each turn. WASDQR etc will move/rotate the follow target manually. Follow target will keep the rotation set by the user, as the new turn code will move it to the new unit's position, not rotate it.

    That should do the job, I think.
     
  3. ciaran_unity342

    ciaran_unity342

    Unity Technologies

    Joined:
    Jun 7, 2018
    Posts:
    2
    This is great, and worked perfectly! thanks so much.
     
  4. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    This is a really strange place for this thread to be.
     
    AnomalusUndrdog likes this.
  5. yodda

    yodda

    Joined:
    Nov 3, 2016
    Posts:
    23
    i always put 3d sphere and mute render and colliders and then let the Camera look or follow that.