Make camera collider ignore tree trunks but not terrain

My camera collider makes my camera zoom in and out as I pass by trees in my forest. I set the camera to ignore the default layer but then it ignores the terrain too and also any objects like my tents. I could put the tents on another layer and I could live with the camera not colliding with the terrain, but ideally I’d love it to just ignore my terrain trees, but it seems like the tree collider share the same default layer as the terrain they’re a part of. Do you have any solutions? Btw I absolutely love cinemachine, I use it cot all my camera needs including the player camera and it works great even on mobile (which is all I target)

If you could move the trees (and other things you want the collider to not consider) to a separate layer, then you could add that layer to the “Transparent Layers” mask in the CM collider:

5841424--620158--upload_2020-5-13_7-27-42.png

Alternatively, you could put a small number here, so that passing occlusions are ignored until they have lasted a minimum length of time:

5841424--620161--upload_2020-5-13_7-29-3.png

1 Like

In your terrain settings you can check ‘Preserve Tree Prototype Layers’ so your trees use the layer assigned originally to the tree instead of the same layer as the terrain.

If you are using MapMagic here unfortunately that setting is not exposed in the MapMagic terrain settings but you can hard code it. Go to MapMagic - Main - Chunk.cs and look for:

#if UNITY_2018_3_OR_NEWER
    terrain.drawInstanced = magic.drawInstanced;
    terrain.allowAutoConnect = magic.autoConnect;
#endif

Change it to:

#if UNITY_2018_3_OR_NEWER
    terrain.drawInstanced = magic.drawInstanced;
    terrain.allowAutoConnect = magic.autoConnect;
    terrain.preserveTreePrototypeLayers = true;
#endif
3 Likes

Thank you. This sounds exactly like what I need. I do use mapmagic - thanks for catching that and for the mapmagic specific mention. I will try this out today.

Thanks also Gregoryl for the info about the zoom speed. That will come in handy too:)

1 Like

Worked like a charm - thank you both :slight_smile:

1 Like

As far as I can tell, this no longer works. preserveTreePrototypeLayers seems to not function in Unity 2021.3.19f1

The MapMagic fix is working in Unity 2022.3.10