Search Unity

How rotate virtual camera to follow player?

Discussion in 'Cinemachine' started by Sesilla, May 22, 2019.

  1. Sesilla

    Sesilla

    Joined:
    Jan 3, 2018
    Posts:
    4
    Hi,

    How can i set camera to follow the player (purple box) like img?




    The situation is a 2.5 scene, the camera follow right the player in horizontal direction. If the player turn 90 degree, the camera follow the player from behind. I would the the camera rotate 90 degree to follow the player always side.

    Thanks in advance
    Sesilla
     

    Attached Files:

    • Img.jpg
      Img.jpg
      File size:
      85.2 KB
      Views:
      569
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Can you show the inspector for your virtual camera?
    Also, does the box rotate when it turns around the corner?
     
  3. Sesilla

    Sesilla

    Joined:
    Jan 3, 2018
    Posts:
    4
    Hi Gregoryl,

    thanks for your reply. In attach the code.

    Thanks in advance
    Sesilla
     

    Attached Files:

  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    ok, I understand. You have to arrange to set the Y rotation on the vcam to reflect the viewpoint you want (try adjusting in in the inspector when playing). You can do this with a custom script that considers your set and the direction of motion of the player. There is no way for CM to do this automatically, as the correct viewing angle cannot be deduced. From the left side, or from the right side? Depends on the surroundings and on the game.
     
  5. Sesilla

    Sesilla

    Joined:
    Jan 3, 2018
    Posts:
    4

    Hi Gregoryl,

    Can you help me with custom script?

    Thanks
    Sesilla
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Maybe there's another way (I don't know, it depends on your game. I don't have enough info).

    Maybe you could set up 4 vcams with framing transposers, one pointing in each direction N, E, S, W. Put trigger colliders on the track sections, and add the CinemachineTriggerAction script to activate the appropriate vcam when the character goes onto that section of track. Let CM brain blend between the vcams.