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

Introduction

Similar for any other Unity project, you'll need a Photographic camera in your level to see the action. The Corgi Engine includes a few Photographic camera specific scripts. Notation that you tin use any Camera script with the asset, or implement your own, or build on pinnacle of the provided scripts. There's zilch mandatory here and you can do whatever you want. This folio covers the main scripts and how to use them.

Regular and UI Cameras

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

By default, in near demo scenes of the Corgi Engine, you'll notice two cameras : a regular camera (2D, 3D, post-obit the role player or not, etc) and a UI Camera. The UI Camera'south Culling Mask is prepare on UI, which means it'll only render UI tagged stuff, and is setup to be superimposed over the principal photographic camera'south render.

CameraController

The CameraController component can exist added to whatsoever camera (orthographic or perspective), and information technology'll make it motility and try to follow the thespian. By default it'll center on your main graphic symbol (the first playable Grapheme y'all'll fix 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 Photographic camera offset will be applied at all times. The Horizontal Look Distance will exist applied when moving left or right. Same thing for the upwards/downwards look distance. And you can also define with the LookAheadTrigger value how much you need to motility for that offset to utilise.

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

The nugget besides includes a multiplayer photographic camera controller. It's basically the same thought as the single player i, simply it'll rails all playable characters in the scene.

Cinemachine

The Corgi Engine supports Cinemachine natively since v6.0. You'll observe examples of information technology in use in the Retro demo scenes (and others). This documentation won't cover all the details of this amazing tool, caput over to Cinemachine's own documentation to learn more than about it.

To add Cinemachine to your scene, you lot tin simply go to the Cinemachine carte du jour and create a new virtual camera. To go far piece of work with the Corgi Engine, you lot'll demand to add a CinemachineCameraController component to it. In it yous'll be able to define whether you want it to follow the player, the expected speed of the player, orthographic or perspective zoom settings, etc. Information technology's relatively similar to the regular camera controller.

Pixel Perfect

From the CameraController's inspector, you'll also be able to set up 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 tin can happen that a sprite is not rendered correctly, as each pixel of your sprite might non end upwards on 1 rounded screen pixel. To avoid this, hither are a few things you can do :

  • Create your assets for a target vertical resolution (768px for example), and set that value every bit 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'southward inspector.
  • On your sprites, fix compression to None, and Filter Mode to Signal (no filter).

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

Parallax

The Corgi Engine includes everything you lot demand to add parallax effects to your game. In that location are basically two ways to do it.

  • 3D Parallax : the easiest style, built-in in Unity, is to have a 2.5D scene. Meaning you take a 3D scene and lateral move from left to right. The Demos/Corgi3D/3DLevel demo scene is a expert showcase of that. You don't demand anything in detail for it to work, only position some elements further from the camera than your main plane (the plane where the grapheme moves) and they'll move slower from left to right when your character moves (and the camera follows). Position them betwixt the photographic camera and your main plane, and they'll appear to motion faster when the camera moves.

  • 2nd Parallax : to achieve the aforementioned effect in second though, you'll need the assist of a few of the Corgi Engine'south scripts. Starting time of all, you'll demand a Camera, with a CameraController script on top of it. You tin can gather one yourself, or copy one from the Minimal demo scene. On that photographic camera y'all demand to add a ParallaxCamera component, and leave its MoveParallax checkbox checked. And then, on whatever gameobject in your scene that you lot want to motility on sync with the camera movement, y'all 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 motility), and whether or non 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 cheque the consequence, or simply, while in editor mode, move the photographic camera around and come across how these elements react. This is useful for artists and level designers, you tin check where a background element volition exist when the photographic camera reaches a certain position. All that'due south left to do is suit speed values to give an impression of depth if you have more than one airplane. For instance, if you accept three background elements : a tree, a mountain and the moon, respective values of 0.5, 0.iii 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 lot to mucilage a sprite to the camera, and information technology'll just follow it everywhere. Mostly used for skies.

Screen shakes

Screen shakes are the best. The engine is built with game feel at its core, and the MMFeedbacks library, included every bit a gift in the engine, is entirely defended to that.

There are multiple ways you can add together screen shakes to your game in the engine, the recommended style is to use Cinemachine for your camera, and the Cinemachine Impulse system to handle screen shakes. This ties in nicely with the engine that supports it, and with MMFeedbacks which let y'all trigger them painlessly. Y'all tin learn how to setup Cinemachine cameras above on this very page, and you can learn how to use MMFeedbacks to trigger shakes in MMFeedbacks' documentation.

Alternatively, you lot can use the legacy CameraController included in the engine, it as well handles screen shakes, that can also be triggered via MMFeedbacks, or via events, like then :

                          MMCameraShakeEvent              .              Trigger              (              duration              ,              amplitude              ,              frequency              ,              faux              ,              0              );                      

For example, this would trigger a relatively mild and brusque shake :

                          MMCameraShakeEvent              .              Trigger              (              0.05f              ,              1f              ,              0.02f              ,              false              ,              0              );                      

Y'all can achieve the aforementioned event by creating a MMFeedbacks object in your scene, adding a CameraShake feedback to it, and having the aforementioned settings.

Lastly, you can use the MMCameraShaker component, which will work with the Wiggle component.

Information technology'south recommended going the Cinemachine mode, information technology's by far the most Unity native, powerful and future proof of all these options. You'll discover examples of screen shakes in activity in pretty much all the demos (the RetroCorgi ones for example). And yous tin can acquire more virtually MMFeedbacks on the defended website and the associated documentation. If you already own the Corgi Engine, do not buy MMFeedbacks twice, information technology's already included in the engine as a souvenir already, no demand to buy it twice :)