How to keep player at the bottom of Dead Zone in Cinemachine

Hi,

I am using Cinemachine in my Unity 2D game for mobile. I have defined Dead Zone for Y axis only (only Jump). So during jumps, the camera moves after a certain limit. When game starts very first time, the Dead Zone pointer (yellow dot) stay at the bottom - or player stays at the bottom of Dead Zone (Please refer the snapshot). This enables me to show the screen (and objects) as I want to cover. My game has various levels or stories (up and down) in a scene. So player needs to either go or up many times. When player climbs to upper level, or go down to lower levels, Dead Zone does not put the player that the bottom (like it does when game starts very first time, as in snapshot). This shows the screen in a weird manner (showing much of the bottom surface and hiding the upper floor, as in snapshot). This would be fixed only when player jumps once, camera follows it and then when player lands, then only the screen put the player at the bottom of Dead Zone. What I want is player should always remains at the bottom of the Dead Zone, not in the centre. I have tried with many settings, like offset, Screen Position, but nothing works. Any help is really appreciated.

There is no setting in Cinemachine that will automatically produce the behaviour you want. You need to do a little scripting.

I would do it by creating an invisible GameObject that casts a “shadow” of your player. Write a custom script which tracks the player’s X position, but puts the Y position on the ground under the player. So it’s tracking your player, but not the jumps. Use that as your camera target instead of the player.

Thanks for your reply. I tried your approach, but it is making the actual player movement jittering. Also there is no damping during the jump, so camera moves very fast to player’s position after the jumps (probably it is because I was holding the Y position during the jump, and setting it shadow player right after actual player’s landed on the ground).

P.S. I am updating Player’s position to shadow player in the FixedUpdate().

Ok, So after posting here, I have tried updating the shadow player’s position in the Update() and jittering issue has gone. But the second issue is still there (Camera moves very fast after the jump ended (Player lands on the ground)).

Increasing the Y damping in the PositionComposer should fix this.

I have tried setting a higher Y damping value (even as higher as 100), but it still does not work.

Here is my code for Shadow Player. “This” is the Shadow Player. This code is attached to Shadow Player as script.

private void Update()
        {
            X = player.transform.localPosition.x;
            Y = this.transform.localPosition.y;

            if (player.isGrounded)
            {
                Y = player.transform.localPosition.y;
            }

            this.transform.localPosition = new Vector2(X, Y);
        }

The hard snapping is because you’re moving the shadow instantly out of the deadzone, which forces the camera to snap.

I’d update your Shadow Player Script to lerp really fast instead;

if (player.isGrounded)
    y = Mathf.Lerp(y, player.transform.position.y, Time.deltaTime * 10f);

Thanks. It did make a difference but damping is still not that smooth as it was when Virtual Camera was following actual the Player. The camera still snaps hard to Shadow Payer only that now it gets still (stops) a bit smoother.

The dead zone is the culprit. Set the Y dead zone to 0, and set the damping to something reasonable, like 0.5. You don’t need the lerp.

No success this time as well :sad_but_relieved_face:. Off course there are improvements over Lerp, but still camera snaps.

I am curious if anyone had really tried this approach and get it worked? Because I am thinking as we are holding Y’s value and then suddenly setting it (when player is on ground), so how camera will follow smoothly? Because in normal scenario, camera smoothly follows the actual player (X & Y) over the time, there is no surge or changes in any values (like Y in our case).

The camera won’t snap if there is damping and no dead zone. Please show your results and your settings.

Sorry for the late reply. Here is the requested details.

Increase the Y damping. You can also add the lerp back in to soften it.