A FreeLook's top rig can escape ceilings?

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!

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.

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.

7896745--1005727--test.gif

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!

1 Like

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!

using UnityEngine;
using Cinemachine;

public class Player_LookTargetOffsetter : MonoBehaviour
{
    [SerializeField] CinemachineFreeLook playerFreeLook;
    [SerializeField] CapsuleCollider playerCapsuleCollider;
    [SerializeField] float maximumOffset = 1.0f;

    private CinemachineComposer bottomComposer;
    private RaycastHit hit;
    private Vector3 capsuleCenter;

    void Start()
    {
        bottomComposer = playerFreeLook.GetRig(2).GetCinemachineComponent<CinemachineComposer>();
    }

    void Update()
    {
        capsuleCenter = playerCapsuleCollider.center + transform.position;

        if (Physics.Raycast(capsuleCenter, Vector3.up, out hit, maximumOffset))
        {
            float offset = hit.point.y - capsuleCenter.y;
            bottomComposer.m_TrackedObjectOffset.y = offset - maximumOffset;
        }
        else
        {
            bottomComposer.m_TrackedObjectOffset.y = 0.0f;
        }
    }
}

Reference: https://discussions.unity.com/t/794904

7897360--1005835--test3.gif
7897360--1006462--test4.gif