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

Cinemachine Collider clipping through floor

Discussion in 'Cinemachine' started by alexcarlson2, Dec 20, 2019.

  1. alexcarlson2

    alexcarlson2

    Joined:
    Jan 11, 2015
    Posts:
    2
    The Collider component works great for walls, props, etc, but for some reason fails on sloped surfaces. Doesn't matter which strategy I use, they all clip through the floor.

    https://gph.is/g/a916xO5

    I also tried writing my own little avoidance script, which does some raycasting, and translates the virtualcamera directly if it's too close to an object. this... also doesn't work at all? I know I used to handle some orbiting stuff this way a couple years ago, but it must have changed, or my free look camera settings got messed up somehow. I'm not sure.

    Code (CSharp):
    1.         if(Physics.SphereCast(cam.position, castRadius, cam.forward, out hit, castDistance)){
    2.             Debug.DrawLine(cam.position, hit.point, Color.red);
    3.             Debug.DrawRay(hit.point, hit.normal, Color.magenta);
    4.             Vector3 dir = hit.normal.normalized;
    5.             transform.position += dir;
    6.             return;
    7.         }
    for example, that code doesn't adjust the camera up, or in any direction at all.

    Any suggestions on what might be wrong here?
     
  2. alexcarlson2

    alexcarlson2

    Joined:
    Jan 11, 2015
    Posts:
    2
    Okay, I think I maybe answered my own questions here kind of. I ended up fixing the clipping by just fussing with the numbers for a while. I read from another forum post that the code above won't work directly on the gameobject that has the orbit camera, but if I change the parenting around, that code should work fine in theory, but I don't think I need it actually, now.
     

    Attached Files:

  3. Catsploration

    Catsploration

    Joined:
    Mar 9, 2021
    Posts:
    68
    I also had this issue, and also needed to "fuss with the numbers." Distance Limit in particular is one to consider changing, in case anyone else finds there way here.