Cinemachine confiner w/ background

Hi all,

In my project I have a Cinemachine vCam following my player and my background image is a child of this camera. I decided I wanted to confine this camera to bounds of my tiles. The confining itself works great.

However, my background image is following my player and thus when the camera gets confined to a border the image continues moving, exposing the base colour of the camera (the blue area)

Same thing happens on the y axis.

I’ve tried clamping the vcam and taking out the confiner with no luck. I figured maybe I could script something that could detect when the confiner is in action and… do something to the image?

This has stumped me for hours. Would appreciate any suggestions.

Edit:

The best way to describe the issue is that the background image is static when the camera is constantly moving. As soon as it stops (due to confiner) it becomes obvious the image is following the player. I guess I need the image to freeze when the confiner starts doing its thing?

This is because the confiner’s effect is not baked into the vcam’s transform.

The simplest fix would be to put the background as a child of the Unity camera, not of the vcam. Then you’d have a fixed background 100% of the time. If that’s not appropriate, you could fix your problem by adding a custom extension on the vcam to cause the confiner’s effect to be propagated to the vcam’s transform. Let me know if you want to do the latter, and I’ll help you with it.

Hey @Gregoryl , appreciate the reply.

Attaching the background to the Unity camera does indeed do what I want. I then ran into the same issue with 4 images separate to the camera that are scripted to follow the vcam and create a parallax scrolling effect. I fixed the issue by scripting them to follow the main camera instead.

Now the only issue I’m left with is that the parallax scrolling stops when reaching the confiner’s bounding box, but that’s a small price to pay to get it all working.

1 Like

Hey @Gregoryl sorry to bring up an old topic but I’m having the same problem that patrick but I want the opposite of what he mentioned, I would like if the parallax effect stoped when the camera reach the confiner. Bellow i attached a gif of my behaviour
unsteadyblanddevilfish

@Xixiberto your problem seems to be that you are attaching your background to the player or to the vcam. Attach it to the main camera (the one with the CM brain) instead.

1 Like

@Gregoryl Thank you so much! That one did the trick, justo for reference and if anyone else get’s into this problem I want to show the parallax script I’m using with TileMap. At first it will look jittery but once you put Interpolate in the Player’s Rigidbody2D looks good.

[SerializeField]
    private Transform cam;

    [SerializeField]
    private float relativeMove = .3f;

    [SerializeField]
    private bool lockY = false;

   
    // Update is called once per frame
    void Update()
    {

        if (lockY)
        {
            transform.position = new Vector2(cam.position.x * relativeMove, transform.position.y);
        }
        else
        {
            transform.position = new Vector2(cam.position.x * relativeMove, cam.position.y * relativeMove);
        }

    }
1 Like