Search Unity

Question Hard Lock to Target + Cinemachine Collider = buggy camera collision

Discussion in 'Cinemachine' started by imaginationrabbit, Sep 13, 2022.

  1. imaginationrabbit

    imaginationrabbit

    Joined:
    Sep 23, 2013
    Posts:
    349
    I have a Dark Souls like lock on system working nicely using a Hard Lock to Target camera- I would now like to get camera collision working with it so I added a Cinemachine Collider- no matter what settings I use I cannot seem to get any consistent/non buggy camera collision out of it-

    The camera either pops through to the other side of the walls or randomly goes underneath the floor- its not usable.

    I have camera collision working perfectly with the 3rd person follow cam and its built in camera collision options but when selecting Hard Lock to Target there's no built in options so I'm using the Cinemachine Collider component.

    I know my layers and colliders are setup properly as the 3rd person follow cam's collision works perfectly.

    I searched through the threads here and tried all the different settings but I can't get any decent behavior out of the Hard Lock to Target camera. Any ideas? Thank you
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    CinemachineCollider uses the offset between camera position and LookAt target as a hint when choosing how to de-collide the camera. If you've hard-locked the camera position to the target, then CmCollider no longer knows how to de-collide consistently.

    How to fix this? I can think of these options:
    1. Create a dummy LookAt target object somewhere in front of your player.
    2. Write your own decollider extension that uses a different algorithm.
    3. Attach a Collider to the target you've hard-locked to, then the camera will automatically not penetrate objects because its target doesn't.
     
  3. imaginationrabbit

    imaginationrabbit

    Joined:
    Sep 23, 2013
    Posts:
    349
    Hey thanks for the reply- I switched the lock on camera to a 3rd person follow type as well- it doesn't give the exact behavior I want but the collisions work nicely- I'll try out these solutions with hard lock when I get a chance- thank you.
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    3rdPersonFollow is a good alternative because it has its own built-in collision resolution.
     
  5. imaginationrabbit

    imaginationrabbit

    Joined:
    Sep 23, 2013
    Posts:
    349
    Yes the built in collision resolution is very nice- any tips on getting 3rd person follow to act more like Hard Lock to target? Thank you.
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    You mean apart from setting all the rig offsets to zero? What is the specific difference in behaviour that you want to eliminate?