Rotate camera along an axis to not be obstructed

I’ve got my camera all set up the way I want it to follow the character around. sometimes the character can go behind walls. I could use a shader to make it glow, or stencil, or something. But I’d like to try and tilt the camera a few degrees to have a better view of the target.

I couldn’t find anything out of the box for this. What I’ve tried is to write a script that would do a line cast between my character and my camera. If there was something there on the obstruction layer then I would try to Lerp the camera’s rotation to have an unobstructed view.

That for the most part worked. I would just find the preferred rotation to have a view of the character and then assign it using the transform.rotation. While this works it’s got some weirdness. Like the camera will bounce around when trying to get a better view. I’m currently under the impression this is so because after rotating the camera the camera’s transform.position changes and then the bouncing is hard to avoid.

I’m trying to keep the camera at a rotation of 70,0,0 but the max would be 85,0,0 if the character was obstructed. Is there something I’m missing that would allow this? I’m currently only using the FollowTarget and a Framing Transposer. Or just some ideas on how to go about achieving the desired effect.

In general you are doing it the right way. Can you describe “bouncing around” in a little more detail? I don’t really understand what you mean. The Framing Transposer algorithm will start with the vcam’s rotation, then move the vcam so that it’s in the desired relationship with the target, while keeping the rotation fixed.

What version of CM are you using?
Can you show an image of the vcam inspector?

Hey there. Sorry for the delay. Been on a tools task the last couple of days.

Cam version: 2.6.0

Here is a gif of the jitter. Red means it’s obstructed, Blue means it’s got a view.
6228666--685362--Camera gitter.gif

Here are the VCam settings:
6228666--685368--VCam Settings.JPG

And because I believe this is most likely a logic issue, here is the relevant code snippets.

void Update()
{
    if (TargetCharacter == null) return;
    var targetPos = TargetCharacter.transform.position;
    var speed = Speed * Time.deltaTime;
    if (Physics.Linecast(transform.position, targetPos, ObstructionMask))
    {
        Debug.DrawLine(transform.position, targetPos, Color.red);
        RotateToward(MaxRotation, speed);
    }
    else
    {
        Debug.DrawLine(transform.position, targetPos, Color.blue);
        if (!IsPositionObstructed(PreferredRotation, speed))
        {
            RotateToward(PreferredRotation, speed);
        }
    }
}
private bool IsPositionObstructed(Vector3 targetPosition, float speed)
{
    var t = Vector3.Lerp(transform.rotation.eulerAngles, targetPosition, speed);
    Debug.DrawLine(transform.position, targetPosition, Color.yellow);
    return Physics.Linecast(transform.position, t, ObstructionMask);
}
private void RotateToward(Vector3 targetRotation, float speed)
{
    var q = Vector3.Lerp(transform.rotation.eulerAngles, targetRotation, speed);
    var a = q - transform.rotation.eulerAngles;
    if (a.magnitude > Deadzone)
    {
        transform.rotation = Quaternion.Euler(q);
    }
}

I still don’t quite understand what you mean by “bouncing around”.
Does it bounce around if you turn damping to 0?

If that stops the bouncing, try checking this option: