Search Unity

Cinemachine FreeLook Camera that doesn't go under floor/terrain

Discussion in 'Cinemachine' started by rtilton1, Feb 26, 2019.

  1. rtilton1

    rtilton1

    Joined:
    Jan 4, 2017
    Posts:
    62
    I'm using a Cinemachine Free Look camera for a 3D side-scrolling game. I have the camera's follow and lookAt set to my character. It's working great, but I'm trying to figure out the best way to avoid the camera going under the floor/terrain. My floor/terrain is bumpy and sometimes it goes underneath it as the foreground terrain where the camera is - is higher in Y position than the character.

    My instinct would be to shoot a ray down from the camera position and ensure the camera's y.position never goes below the floor based on a RaycastHit info...With the freelook camera I feel that I should adjust the Y-Axis under Axis Control to ensure the camera doesn't go under the floor, but adjusting the Y-Axis proves difficult to get it to feel smooth as the axis value isn't linear to hit distance of the ray.

    I bet Cinemachine has a better way built in, but I can't seem to find it via google search or videos. Any advice on this would be appreciated.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    You can try adding a CinemachineCollider to the FreeLook.
     
  3. rtilton1

    rtilton1

    Joined:
    Jan 4, 2017
    Posts:
    62
    Wow! This works perectly. Never seen these extensions before... For others who google this. In the Inspector > FreeLook component > Extensions > Add Extension > CinemachineCollider

    Thanks greg!
     
    Ensortainment and ConAim like this.