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

A FreeLook's top rig can escape ceilings?

Discussion in 'Cinemachine' started by Blepius, Feb 13, 2022.

  1. Blepius

    Blepius

    Joined:
    Mar 9, 2021
    Posts:
    68
    If the Cinemachine's rig path is able to be completely on the other side of a ceiling, then it seems to like to go over there when player jumps.

    In this room, I've created a thick box collider along the ceiling to rule out problems that could come from a thin mesh, but there is a room above, so there are limits on how thick the box collider can be.

    Any ideas on how I can keep the camera within the room? Thanks!



    upload_2022-2-12_23-8-42.png

    upload_2022-2-12_23-9-30.png

    upload_2022-2-12_23-10-2.png
     
    Last edited: Feb 13, 2022
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,296
    With these settings, the camera should stay on the same side of the collider as the target. It will go through the ceiling only if the target does.
     
  3. Blepius

    Blepius

    Joined:
    Mar 9, 2021
    Posts:
    68
    My only thought is that maybe this is related to the Kinematic Character Controller (the one by Philippe on the Asset Store) somehow? I know it has fairly complex ideas related to transient position, but I thought most of that would be encapsulated away.
     

    Attached Files:

    Last edited: Feb 14, 2022
  4. Blepius

    Blepius

    Joined:
    Mar 9, 2021
    Posts:
    68
    Ohhh!! As the target, of course.

    The look target is going onto the other side of the wall here even though the player is still in the room.

    Thank you!
     
    Gregoryl likes this.
  5. Blepius

    Blepius

    Joined:
    Mar 9, 2021
    Posts:
    68
    Hm, I'm struggling to find a way to look both up and down while keeping the look targets within the player's hitbox.

    Are there any ideas for this that I'm missing? I've tried the "y offset" setting, but it seems to keep the same behavior as simply moving the look target game objects.

    Edit: The attached test3.gif is kind of a solution, but it's maybe a little disorienting to pull the in camera that close. I'll keep playing with this!

    Edit 2: test4.gif is my second thought for a solution, it seems to work well!

    Code (CSharp):
    1. using UnityEngine;
    2. using Cinemachine;
    3.  
    4. public class Player_LookTargetOffsetter : MonoBehaviour
    5. {
    6.     [SerializeField] CinemachineFreeLook playerFreeLook;
    7.     [SerializeField] CapsuleCollider playerCapsuleCollider;
    8.     [SerializeField] float maximumOffset = 1.0f;
    9.  
    10.     private CinemachineComposer bottomComposer;
    11.     private RaycastHit hit;
    12.     private Vector3 capsuleCenter;
    13.  
    14.     void Start()
    15.     {
    16.         bottomComposer = playerFreeLook.GetRig(2).GetCinemachineComponent<CinemachineComposer>();
    17.     }
    18.  
    19.     void Update()
    20.     {
    21.         capsuleCenter = playerCapsuleCollider.center + transform.position;
    22.  
    23.         if (Physics.Raycast(capsuleCenter, Vector3.up, out hit, maximumOffset))
    24.         {
    25.             float offset = hit.point.y - capsuleCenter.y;
    26.             bottomComposer.m_TrackedObjectOffset.y = offset - maximumOffset;
    27.         }
    28.         else
    29.         {
    30.             bottomComposer.m_TrackedObjectOffset.y = 0.0f;
    31.         }
    32.     }
    33. }
    Reference: https://forum.unity.com/threads/cin...mid-bottom-rigs-tracked-object-offset.908006/
     

    Attached Files:

    Last edited: Feb 16, 2022