Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How to move cinemachine camera also when Character is not moving?

Discussion in 'Cinemachine' started by avataris-io, Aug 17, 2022.

  1. avataris-io

    avataris-io

    Joined:
    Jun 23, 2020
    Posts:
    25
    Hi, I,m using 3rd person virtual camera for 1st person view of the character, everything works fine except that when the character stays static and the head continues to move with IK camera always stays at the same position.

    I noticed that the camera moves only when I use wsda buttons, but the following target also moves even when the character stays in one place because the head is controlled with IK and always changes position depending on the mouse position.
    My goal is to apply this movement also to the camera, so it would also change the movement of the target with IK and place the camera directly to the position of the following target. How can I do this?
    I was trying different cameras and also just adjusting shoulder offset depending on head position, but it didn't work properly... maybe you know how to make the camera always follow the head position (and not only when the character is moved with wsda)?
     

    Attached Files:

  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,233
    Have you tried making the follow target an actual child of the moving head?
     
  3. avataris-io

    avataris-io

    Joined:
    Jun 23, 2020
    Posts:
    25
    yes, it's child of head
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,233
    If it's a child of the head and the head is moving, then the camera should move along with it. It would take work to prevent it from moving. Can you show some images of your hierarchy, with the relevant objects visible?
     
  5. avataris-io

    avataris-io

    Joined:
    Jun 23, 2020
    Posts:
    25
    yes here is character hierarchy
     

    Attached Files:

  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,233
    Hmmm... strange. If the camera is indeed tracking that object, and if the object is moving, then the camera should move.
    Can you try, as an experiment, to put a cube there? Does it move with the head?
     
  7. avataris-io

    avataris-io

    Joined:
    Jun 23, 2020
    Posts:
    25
    yes, cube is moving with head
     

    Attached Files:

  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,233
    Can you use the cube as a Follow target in the vcam? What happens?
     
  9. avataris-io

    avataris-io

    Joined:
    Jun 23, 2020
    Posts:
    25
    well, if I move the cube camera also moves in direction of it, but not precisely at the position of the cube. If I move head then the camera stays in the same position.
    I was thinking that maybe it's because the camera uses local rotation position instead of world position. because when a character is animated local position is always 0, but the global position changes. and it seems like the camera change position only if the object which it follows change its local position and not the world position
     
  10. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,233
    What happens if you replace "3rdPersonFollow" in the vcam with "Hard Lock To Target"? And perhaps "Same As Follow Target" in Aim.
     
    Last edited: Aug 17, 2022
  11. avataris-io

    avataris-io

    Joined:
    Jun 23, 2020
    Posts:
    25
    the camera also stays in the same position and doesn't follow the target
     

    Attached Files:

  12. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,233
    Something is off with your setup, then. When I open the AimingRig sample scene and put the follow target as a child object of the character's head, and adjust the rig settings for 1stPerson, the camera moves with the head's animation.

    What versions of Unity and CM are you using?
     
  13. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,233
  14. avataris-io

    avataris-io

    Joined:
    Jun 23, 2020
    Posts:
    25
    hm, I use unity 2021.3.6f and cinemachine version 2.8.6.
     

    Attached Files:

  15. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,233
    I don't know off-hand what the problem is. If you share a repro project with me, I can take a look at it.
     
  16. avataris-io

    avataris-io

    Joined:
    Jun 23, 2020
    Posts:
    25
    hey! I seem to find the reason. I made the same setup as you did in the AimingRig scene and it was working. Then I added LookAtIK script to the character and set the sphere as a target. And then if I move the sphere in the scene head is moving, but the camera not following it.
    you can also try to replicate it.
    Do you know how to fix it?
     

    Attached Files:

  17. avataris-io

    avataris-io

    Joined:
    Jun 23, 2020
    Posts:
    25
  18. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,233
    Yes, since that thread, a new CM feature was added: manual update. You can add this custom script to your main camera with the CM Brain. Set its execution order to be after FinalIK, as described in the other thread.

    Let me know how it works.

    Code (CSharp):
    1. using UnityEngine;
    2. using Cinemachine;
    3.  
    4. public class ManualUpdateCM : MonoBehaviour
    5. {
    6.     CinemachineBrain brain;
    7.  
    8.     void Start()
    9.     {
    10.         brain = GetComponent<CinemachineBrain>();
    11.         brain.m_UpdateMethod = CinemachineBrain.UpdateMethod.ManualUpdate;
    12.     }
    13.  
    14.     void LateUpdate()
    15.     {
    16.         brain.ManualUpdate();
    17.     }
    18. }
    19.  
     
    avataris-io likes this.
  19. avataris-io

    avataris-io

    Joined:
    Jun 23, 2020
    Posts:
    25
    good, thank you)