Setup top down camera where camera moves when character hits edge

Hi,

So I have been trying to setup a camera that is a topdown camera - following my player character. I want the camera to stay at a consistent distance and angle from my player, and only move when the player gets close to the edge (So very much like a standard 2D camera).

I have been able to set up something approximating this using Cinemachine - but it doesn’t quite behave as expected. Using a virtual camera, with the lookat and follow set to my player character, the camera (with default settings) always tries to keep the player character in the center of the screen.

Interestingly - by removing the Follow reference to the player (on the camera) - the player will move to the edges, and then the camera tracks correctly. But of course, the camera will never move from it’s position.

3226637--247517--always-center-2.PNG

Even when the player character moves - it stays in the center, never reaching the edge… I want the camera to move only when the player hits the blue line - but the camera should stay in the same orientation and follow the player.
3226637--247518--always-center.PNG

Any help would be appreciated!

We’ve recently found a bug where the object stays stuck in the middle even though the blue guides are far aside… Can you try hitting play and or restarting Unity?

We’ve run into this once before, it seems like a super rare bug which pops up sometimes and we can’t track it down.

Please try that and let us know.

When it starts working again - and it will! - this is a weird sometimes bug, take note of the Word Up Override feature on the Cinemachine Brain. CM is designed to shoot things flatly, like a camera person shooting things on the horizon. Looking up and down can get into gimbal lock areas, which we address but it’s outside the ‘nice’ zones for the math.

World Up Override will allow you to rotate the ‘horizon of nice math’ to be downward to match your game

@AsahiChaser Have a look at CM 2.1 (available in beta here: CM v2.1 beta release: New features, new fixes, improvements, examples, ). It has a new feature that I think might be exactly what you’re looking for: the Framing Transposer. It’s a transposer that gets the desired shot framing by moving the camera only - it leaves the orientation alone.

Thanks for the advice - I had a look at what you suggested (I configured a world up override), but I don’t think that was the primary issue. The camera angle, while downward, was not perfectly downward, and even in more shallow situations - it would still be a problem.

But thanks again. :slight_smile:

This is it - works perfectly. Thanks so much for the suggestion - it took longer for the package to install than to configure it. :wink:

2 Likes