DevLog #1: A Matter Of Perspective

As I already told in DevLog #0, Flatlings really found its character when I switched perspective from the original boardgame-y topdown view to a perspective camera. However, this change came with its own list of issues I had to work around as I gave up some of the conveniences of a strictly 2D layout.

Billboarding

Obviously, now that the actors could actually “pop out” of their previous flat confines I needed to make sure they would actually line up to the camera angle. Usually the best way to solve this is using a shader which automatically does all the heavy lifting. Not having wrapped my head around that topic in general I decided to take a rather blunt but more accessible approach instead, though.

Scene view of billboarded sprites

Each sprite that should be billboarded – basically everything except for the ground tiles themselves – has a small script attached to it checking the main camera’s transform.forward value and applies this to the SpriteRenderer as well.

Billboarded “flat” actors on a shifted ground

Since the camera in Flatlings can only be panned and zoomed but not tilted the performance impact should be minimal at best since the script only runs once whenever a sprite is instantiated. Again, a shader might take care of this with much more ease but to me it feels like a slightly overblown solution to a rather small problem.

Pivot Points and Z-Ordering

Now that actors were properly standing around on the map the next issue was making sure units and decoration would be displayed in their proper order so a unit on a further away tile could find visual cover behind a much larger mountain or hide inside a forest.

After a bit of trial and error I found the right setup for Unity to take care of the sorting order. In the Project Settings menu you can adjust the transparency sort settings, telling Unity which axis it should take into account, and how the individual objects and their position in world space should be handled.

But why set the sort mode to Orthographic when we actually have a perspective camera?

As it turns out, whenever objects get closer to the left and right edges of the screen, they might still be positioned behind whatever is in front of them. However, due to the shifted view their distance to the camera’s position might actually be smaller than that of the object in front of them. This does not happen often, but it is painfully noticeable whenever it does.

With the sort mode set to Orthographic this is properly taken care of as Unity only considers the object’s distance to the camera on the z-axis.

It is also necessary to set every actor’s sprite pivot point (visualized by the small blue donut) to the position the sprite will actually touch the ground…

… and set its SpriteRenderer’s sort point to Pivot rather than Center.

Sort Order Settings and URP

One rather odd behaviour of Unity is not allowing you to change a project’s Camera Settings whenever you have set a Scriptable Render Pipeline, e.g. the Universal Render Pipeline (URP).

However, despite the engine’s claims that “… some settings will not be used…” it turns out they still have an impact on rendering even when hidden from the settings menu. If you need to access those all you have to do is temporarily remove the asset from the settings to restore the Camera Settings options, adjust as necessary, and reapply the render pipeline asset again.

(some sources suggest that it might be necessary to save and exit Unity after each of these steps but at some point it seemingly started to work fine even without that, so your mileage may vary here)

Leave a Comment