This page explains how to use cameras in the Corgi Engine.

Introduction

Like for any other Unity project, you’ll need a Camera in your level to see the action. The Corgi Engine includes a few Camera specific scripts. Note that you can use any Camera script with the asset, or implement your own, or build on top of the provided scripts. There’s nothing mandatory here and you can do whatever you want. This page covers the main scripts and how to use them.

Regular and UI Cameras

Jekyll
The Corgi Engine's two cameras, in the hierarchy view, in the scene view (UI to the left, regular camera to the right), and below both camera's separate previews

By default, in most demo scenes of the Corgi Engine, you’ll notice two cameras : a regular camera (2D, 3D, following the player or not, etc) and a UI Camera. The UI Camera’s Culling Mask is set on UI, which means it’ll only render UI tagged stuff, and is setup to be superimposed over the main camera’s render.

CameraController

The CameraController component can be added to any camera (orthographic or perspective), and it’ll make it move and try to follow the player. By default it’ll center on your main character (the first playable Character you’ll set in the scene’s LevelManager). From its inspector, you can define a few offsets, that will be added to this position depending on certain situations. The Camera offset will be applied at all times. The Horizontal Look Distance will be applied when moving left or right. Same thing for the up/down look distance. And you can also define with the LookAheadTrigger value how much you need to move for that offset to apply.

Then you can define movement speed and zoom values, with pretty self-explanatory settings. The final thing you can check is a checkbox that will automatically enable or disable effects on mobile. If you set it off, all standard assets effects added to the camera will be disabled when running on Android or iOS.

The asset also includes a multiplayer camera controller. It’s basically the same idea as the single player one, but it’ll track all playable characters in the scene.

Pixel Perfect

From the CameraController’s inspector, you’ll also be able to set whether or not you want a pixel perfect camera. Most suited for 2D pixel art games, the pixel perfect camera will disable zoom, and instead determine a new orthographic camera size based on your settings in the inspector (the target vertical resolution at which for which you produced your sprites) and your desired PPU (pixels per unit) value.

Without this PixelPerfect setting, it can happen that a sprite is not rendered correctly, as each pixel of your sprite might not end up on one rounded screen pixel. To avoid this, here are a few things you can do :

  • Create your assets for a target vertical resolution (768px for example), and set that value as your Reference Vertical Resolution in the CameraController’s inspector.
  • For each of your sprites, define a common PPU value (32 for example), and set that value as your Reference Pixels Per Unit value in the CameraController’s inspector.
  • On your sprites, set compression to None, and Filter Mode to Point (no filter).

You can also learn more about Pixel Perfect cameras in Unity in this blog post.

Parallax

The Corgi Engine includes everything you need to add parallax effects to your game. There are basically two ways to do it.

  • 3D Parallax : the easiest way, built-in in Unity, is to have a 2.5D scene. Meaning you have a 3D scene and lateral movement from left to right. The Demos/Corgi3D/3DLevel demo scene is a good showcase of that. You don’t need anything in particular for it to work, just position some elements further from the camera than your main plane (the plane where the character moves) and they’ll move slower from left to right when your character moves (and the camera follows). Position them between the camera and your main plane, and they’ll appear to move faster when the camera moves.

  • 2D Parallax : to achieve the same effect in 2D though, you’ll need the help of a few of the Corgi Engine’s scripts. First of all, you’ll need a Camera, with a CameraController script on top of it. You can assemble one yourself, or copy one from the Minimal demo scene. On that camera you need to add a ParallaxCamera component, and leave its MoveParallax checkbox checked. Then, on any gameobject in your scene that you want to move on sync with the camera movement, you can just add a ParallaxElement component.

There are a few options to setup there : vertical and horizontal speed (the higher the value, the faster it’ll move), and whether or not this should move in the opposite direction as the camera. In most cases you’ll want to leave that checked. Then you can either press play and check the result, or simply, while in editor mode, move the camera around and see how these elements react. This is useful for artists and level designers, you can check where a background element will be when the camera reaches a certain position. All that’s left to do is adjust speed values to give an impression of depth if you have more than one plane. For example, if you have 3 background elements : a tree, a mountain and the moon, respective values of 0.5, 0.3 and 0.1 should give a good impression of depth.

One last thing to consider is the LevelBackground script. Useful for 2D levels, it allows you to glue a sprite to the camera, and it’ll just follow it everywhere. Mostly used for skies.