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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Bug FreeLook camera drifting in build only

Discussion in 'Cinemachine' started by boaheck, Sep 23, 2020.

  1. boaheck

    boaheck

    Joined:
    Jan 25, 2014
    Posts:
    4
    Problem:
    My Cinemachine FreeLook camera begins to drift over time. with no input it will bigin to rotate until the camera's y rotation is 180 degrees. This only happens in the build of my game and not in editor so it is really difficult to debug what's actually happening here. The speed at which it drifts seems to get faster the more you play actively. If you start the game up and never do anything the camera does not drift even after 30 minutes. The issue seemed to be more pronounced on my QA testers systems which had better performance. Here's a screenshot containing a graph of the main camera's y rotation over time without any input. the y axis goes from 0 to 360 so as you can see it moves towards 180 and slows down as it approaches.



    Setup:

    Unity Version: 2019.4.8f1
    Cinemachine Version: 2.3.4

    My game is a 3d platformer so I am basically using the free look camera to create third person movement. The movement system is based on a modified version of my own first person movement system. You can find my movement code here https://github.com/boaheck/TheFirstPerson/tree/third-person This is missing a few touches I've added while building the game, I can post an up to date version if needed.

    I have my FreeLook camera as part of a StateDrivenCamera along with a second virtual camera used for looking at npc's during dialogue. This is controled by an animator on a seperate object with state transitions triggered by my npc interaction script. I will include images of the free look camera inspector so you can see the settings used. Both cameras have Cinemachine Colliders on them

    The freelook camera is controled by the Mouse X and Mouse Y axes which also take input from the 4th and 5th joysitick axes. These have deadzones of 0.4 and sensitivities of 1. It is set to both follow and look at my player object in "Simple Follow With World Up" mode. My player rotates based on the Horizontal and Vertical input axes relative to the cameras facing direction, and moves forward in that direction.

    If there's any other details you need please let me know.

    Here's the Freelook Cameras inspector
    upload_2020-9-23_20-49-43.png
    upload_2020-9-23_20-50-16.png
    upload_2020-9-23_20-50-45.png
    upload_2020-9-23_20-51-9.png
    upload_2020-9-23_20-51-36.png



    Things I've tried:
    So now onto the list of things I've already tried.
    - Getting rid of the state driven camera and all of it's behaviour.
    - Removing the Cinemachine collider
    - Both of the above at once
    - Changing the Default blend to linear or to cut
    - Increasing the freelook camera's priority in the StateDriven Camera
    - Adjusting the input deadzones
    - Creating an entirely new Freelook camera

    I would appreciate any help in fixing this as I am on a deadline with this project and have already lost probably 5-6 hours alone trying to fix this. There is every chance it's something I'm doing but I am never modifying the camera rotation or the virtual camera from code and am only retrieving it so I can orientate the player's direction in one place. I hope I'm just missing something obvious here.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,238
    Do you still have the problem if you upgrade to the latest CM 2.6.3?

    EDIT: Have you tried changing the FreeLook binding mode to World Space? Setting it to SimpleFollow can certainly introduce drift, because in that mode there is no concept of absolute forward (other than Camera Forward).
     
    MaxamDev likes this.
  3. boaheck

    boaheck

    Joined:
    Jan 25, 2014
    Posts:
    4
    Thank you! Worldspace seems to have fixed it. Funny enough I used to have the binding mode set to something else when setting up my movement first but went back to SimpleFollow because I prefered how it played. There's a few little issues in the feel of the camera now but I think I can tweak it more to my liking. Thank you for the quick response. I'll definitely try updating if the issue returns and will also post here but I'm pretty sure this resolves it. Thanks Gregory!
     
    Gregoryl likes this.
  4. treborguy

    treborguy

    Joined:
    Apr 17, 2014
    Posts:
    30
    Why even have a camera mode that drifts more and more the longer you play the game? Is there any way to set the forward position manually to remedy the drift?

    I'd really like a solution because using world space locks the camera position relative to the player. I'd like to have the camera be pulled around like in Mario 64, and simple follow does that perfectly, the only issue is the drift. It's so close to perfect, so would really appreciate some help :)

    Thanks!

    Rob

    [EDIT] Disabling and enabling the CinemachineFreeLook component resets the drift temporarily, until it starts drifting again. Obviously using this to fix the drift is a no go, since the camera would have to be off for an entire frame and all the other values on the camera would be reset, but it shows that there's some value somewhere that just needs updating right? Like you say, maybe the forward Vector?
     
    Last edited: Feb 28, 2022
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,238
    This is a very old thread, originally discussing CM 2.3.4. The camera isn't supposed to drift. We have never seen drift in our testing of recent CM versions. If you could put together a lightweight project that reproduces this drift and send it to me, we can look at tracking it down and fixing it.
     
  6. treborguy

    treborguy

    Joined:
    Apr 17, 2014
    Posts:
    30
    Hi Gregory, thanks for the reply!

    Attached an example as requested.

    New project using 2020.3.29f1 and the latest version of CM

    The time scale is set to 10 since the issue builds over time. Moving around using WASD and Mouse will increase the drift.

    The only things I changed from the default settings on the FreeLookCamera were the Orbits, the 'invert' axis settings and the 'Look At' and 'Follow' transforms. However I tested with default settings and the drift still occurred

    If it helps, I just realised that the drift only occurs if the 'Look At' and 'Follow' transforms are children of another Transform, though I can't be sure, maybe it just builds slower when they are children of the world. [EDIT] No it still occurs.

    Cheers
     

    Attached Files:

    Gregoryl likes this.
  7. treborguy

    treborguy

    Joined:
    Apr 17, 2014
    Posts:
    30


    https://imgur.com/UPj92mc

    More notes:

    The camera appears to drift towards 0 degrees y rotation and the drift is worst at 90/-90 degrees. As it nears 180 degrees the drift slows. Overriding the world up vector seems to affect it.
     
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,238
    Thank you very much for preparing that. Using your sample, I was able to repro the drift with CM 2.6.11, but not with CM 2.8.4. If you upgrade CM in your project, does the drift still happen?
     
    Last edited: Mar 1, 2022
    treborguy likes this.
  9. treborguy

    treborguy

    Joined:
    Apr 17, 2014
    Posts:
    30
    Ah! I had no idea I wasn't using the latest version of CM since in the package manager it didn't give me the option to update. Had to click on "see other versions" which I've never had to before apart from to get old versions of assets.

    Yes, that completely fixed the issue, thanks so much! Really appreciate the quick response.
     
    Gregoryl likes this.