Search Unity

Cinemachine Collider conflicting with Third Person Controller

Discussion in 'Cinemachine' started by HeyBishop, Jan 24, 2020.

  1. HeyBishop

    HeyBishop

    Joined:
    Jun 22, 2017
    Posts:
    238
    I'm not sure if I'm posing this question in the right forum, here goes...

    I've been having troubles with my Third Person Controller, in which the character suddenly goes into half-jump pose and floats mid-air - I can no longer control the character apart from spinning it. Obviously, I figured the issue is with the setup of the character, the ridgebody, collider, etc. Then I realize this happened only when CinemachineCollider extension was in use and the line of sight of the character is obscured. That's what triggers this weird behaviour.

    Here is a video capture of the issue in action:
     
    kirbyderby2000 likes this.
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    Can you show something of your setup? I'd like to see the hierarchy for the controller, the Camera, and the vcam. You probably have some kind of feedback situation.
     
  3. HeyBishop

    HeyBishop

    Joined:
    Jun 22, 2017
    Posts:
    238
    Sure!
    I've placed the Third Person Controller prefab from the Unity Standard Assets in my scene, no modifications. Cinemachine> Create Virtual Camera.

    I assigned the Third Person Controller that is in the scene to the Follow and Look At fields of the Cinemachine Virtual Camera script. I adjusted the follow offset and the aim a bit. It works totally fine up to this point.
    Then, when I add the Cinemachine Collider extension - even without making a single change to the extension script, things get funky.

    Is that enough information?
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
  5. kirbyderby2000

    kirbyderby2000

    Joined:
    Apr 28, 2017
    Posts:
    35
    I spent more time than I'd like to admit trying to fix the same exact issue you were having: the Third Person Character would stay in the "Is Not Grounded" state indefinitely while a Cinemachine Collider was present in the scene. The issue lies with the Cinemachine Collider script. Under the hood, the Cinemachine Collider script instantiates a hidden dummy sphere collider Gameobject for future reference collision detections. While this wouldn't be a problem under normal circumstances, the gameobject is instantiated at the maximum floating point value in all 3 axis, which I believe is causing Unity's collision detection to go berserk. You need to edit CinemachineCollider.cs directly to fix this issue.
    Find the following line:
    Code (CSharp):
    1. mCameraColliderGameObject.SetActive(true);
    And then replace it with:
    Code (CSharp):
    1.  mCameraColliderGameObject.SetActive(false);
     
    mostafa3dblender likes this.
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    @kirbyderby2000 Thanks for the feedback. The issue you mention was fixed a long time ago. Are you using a very old version of Cinemachine, perhaps the one from the Asset Store? If so, then you can upgrade to the latest via Package Manager.
     
    kirbyderby2000 likes this.
  7. kirbyderby2000

    kirbyderby2000

    Joined:
    Apr 28, 2017
    Posts:
    35
    Ah, good to know. I'm using Cinemachine 2.1.10. Also not sure if this matters but the project I'm working on happens to be made in 2018.3.0f2, too scared to upgrade my project to the latest version of Unity though haha.
     
    mostafa3dblender likes this.
  8. albertoha94

    albertoha94

    Joined:
    Apr 14, 2015
    Posts:
    2
    Hey, just wanted to do an update saying that I had this issue too and was able to solve it by applying @kirbyderby2000 solution.
    This was on Cinemachine 2.1.10 & Unity 2019.4.8f1.
     
  9. HeyBishop

    HeyBishop

    Joined:
    Jun 22, 2017
    Posts:
    238
    WOW. Such a crazy coincidence. I haven't used Cinemachine since I last posted in this thread... until today - I put it to use. I'd nearly forgotten it existed!

    I plan to resurrect this project, so I'm happy to see there's a solution!
     
  10. mostafa3dblender

    mostafa3dblender

    Joined:
    Dec 5, 2019
    Posts:
    1
    Hi i have same problem with unity 2020 and Cinemachine that i download form unitypackage manager . i dont have CinemachineCollider.cs script instead i see CinemachineColliderEditor.cs and CinemachineColliderPrefs.cs and none of them have that script you said what should i do ?
     
  11. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    Do you have an asmdef file in your project? If so, you will need to explicitly add to it any package dependency assemblies, such as Cinemachine. As a test, you can try making an empty project and installing Cinemachine.