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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Following The Leading Object During the Game Time

Discussion in 'Cinemachine' started by MorlockProblems, Dec 16, 2022.

  1. MorlockProblems

    MorlockProblems

    Joined:
    Dec 2, 2021
    Posts:
    4
    I want my camera to always follow the object moving forward. In short, when another object takes the lead, my camera focus should shift to it. How can I do that.
     
  2. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    The best way would be to have a CinemachineVirtualCamera (vcam) for each object. Have all vcams all disabled. Only enable the vcam that is tracking the object in the lead.

    This way you have easy control over blending between cameras.
     
  3. MorlockProblems

    MorlockProblems

    Joined:
    Dec 2, 2021
    Posts:
    4
    By calculating the distance of all objects until the finish. I can check which is closest to finish. But wouldn't that cause problems in terms of performance? Because I have too many objects in the scene. Is there a better way I can do this?
     
  4. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    This is not a Cinemachine question. You may get better answers on other forums.
    Probably there are a lot of ways to optimize the calculation based on how the race track is setup. For example, you could trim down the number of objects to check by dividing the race track into regions. Also, you can use distanceSqr, instead of distance to save on square roots.
    There are, for sure, more optimizations to do once you analyze your data.


    Since Cinemachine Virtual Cameras are all disabled, and only one is active, the solution I proposed would not cause a performance problem.
     
    MorlockProblems likes this.