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

Question Cinemachine Confiner 3D. Multiple box colliders or mesh collider?

Discussion in 'Cinemachine' started by Jbaker08, Mar 2, 2023.

  1. Jbaker08

    Jbaker08

    Joined:
    Oct 8, 2012
    Posts:
    52
    I have a camera that follows a player in 3d space, my map isn't one square though, there are different areas I want to stop the camera from going, this would be an easy fix if I could use multiple box colliders or a mesh collider in the confiner but I don't seem to be able to.

    Is there something else I can do?

    thanks
     
  2. Jbaker08

    Jbaker08

    Joined:
    Oct 8, 2012
    Posts:
    52
    Just a quick note:
    I've tried changing the confiner when the player collides with a new one.
    This resulted in the camera jerking when I enter the new area, I'm assuming this is due to resetting parameters or something when a boundary box is newly defined or changed.

    I've tried making my confiner a big box and then creating smaller boxes that act as colliders, then using the collision extension. This resulted in the best result so far but still created some weird camera jerking and zooming right in on my player, even though I set the parameters to not do that.

    I've tried multiple box colliders inside one gameobject. Didn't work at all.

    Wrote my own script to confine the camera game object within a mesh collider however it seems the virtual camera settings are overriding any transform position I'm modifying.

    None of these have worked. I'm surprised there isn't an easy way to do this.
     
  3. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,238
    If you've done the work to write a script that confines to a mesh collider, then you can package that code in a custom CinemachineExtension to fit in the CM pipeline and play well with the other components. Start with CinemachineConfiner.cs, copy it, rename it, and replace the confining code with yours. It should work.
     
  4. Jbaker08

    Jbaker08

    Joined:
    Oct 8, 2012
    Posts:
    52
    Well honestly, I was using a very different method to how the the base confiner works and it's still not working so I'm assuming the Cinemachine Camera uses a different system entirely to confine the camera.

    Why doesn't it support multiple bounding boxes? Seems like an obvious thing considering very few games lock players into a single box.
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,238
    You can use a convex MeshCollider with the CinemachineConfiner. Have you tried that?
     
  6. Jbaker08

    Jbaker08

    Joined:
    Oct 8, 2012
    Posts:
    52
    You cannot.. unless it's an added thing?
     
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,238
    You can do it with the current version of CM (2.9.5). What version are you using?