Context sensitive camera behavior for my top down game.

I’m working on a system to drive a top down camera around a level I am setting up. The game is mostly on rails, with auto scrolling segments composing the majority of the game. But some rooms, especially bonus rooms, or rooms that allow for free movement need to be supported. I need to be able to adjust behavior in the inspector, and I should be able to handle branching paths when the time comes.

I have a nearly working solution, but I can’t serialize a reference to a class inside of itself. That was important for making one of the camera modes work as I had envisioned it (the wait for player to walk to edge of screen before continuing to another state state specifically). So it doesn’t work without some restructuring. And I’m a bit stumped.

So I’m calling on the forums to help me think through the problem. What would your general solution to this problem look like? And how would you define camera behavior at each point, such that it can be efficiently edited in the inspector? Some fresh perspective ought to help me quit overthinking it.

The level I’m building right now looks like this:

  • Start at p0.

  • Prompt player to Go->, begin scrolling when they do.

  • Scroll to p1.

  • Wait for player to destroy barrier.

  • Prompt player to Go->, resume scrolling when they do.

  • Quick transition scroll to p2.

  • Slight delay.

  • Scroll to p3.

  • Wait for defined set of enemies to be killed

  • Prompt player to Go->, resume scrolling when they do.

Anywhere within this sequence, the player could find a secret and branch to a room where the camera follows them, but is constrained to stay inside of a box.

Well, it is possible to reference other reference type objects - specifically within the same UnityEngine.Object - with SerializeReference.

Though custom inspector work, or addons like Odin Inspector, is required to make full use of Unity’s new serialisation system.

Though in your case, you could easily just make each of these individual actions their own components, and just attached a bunch to one or more objects. Or you could have separate trigger game objects that just give the camera an instruction.

Camera stuff is pretty tricky… you may wish to consider using Cinemachine from the Unity Package Manager.

There’s even a dedicated forum: Unity Engine - Unity Discussions

In your case it might be best to make a virtual camera for each case / need, then a system to switch between them based on triggers or other volumes.

You might be right. But when I tried this I found it to make the handling of my game’s skewed perspective more complex. I was turning off more features than I was using. I’m easily overwhelmed, so I justified dropping cinemachine by telling myself I want to do this for the sake of education, in hopes that I could get by just by rolling a simple and specific system.