Tag Archives: unity

Pixel Perfect Calculator for Orthographic Camera : Unity3D

It’s pretty easy to setup an Orthographic Camera in Unity, but without paying attention the settings can cause us numerous problems when it comes to sprites, textures and the quest for pixel perfect graphics in our games.

When wanting pixel perfect graphics it is important that we set the camera size to give us a 1:1 pixel/texture ration between Photoshop (or your alternative) and Unity.

For example, if our game resolution is set to width = 960px height = 640px and our camera size is set to 5 a Unity cube (scaled at 1,1,1) will be the equivalent of a 64px by 64px square in Photoshop. This means that our game screen will have space for ten 64px sprites stacked on top of each other.

Camera Size Explaination

Many game devs will prefer to work with a set size in Photoshop and then adjust their camera setup in Unity accordingly. Depending on the resolution and the target Photoshop size this can require some complicated trial and error. However an untraceable contributor  in the comments section of Rocket 5’s wonderful tutorial series on 2D in Unity , provided a formula thus avoiding the trial and error.

Camera Size = x / ((( x / y ) * 2 ) * s )

Where:
x = Screen Width (px)
y = Screen Height (px)
s = Desired Height of Photoshop Square (px)

It’s a formula that works perfectly and I have setup a calculator to make the calculation process even easier via my Pixel Perfect Camera Size Calculator – Google Doc. Feel free to share, use and download as you wish.

Pixel Perfect Calculator
Pixel Perfect Calculator
Advertisements

Orthographic Camera Setup

An orthographic camera is commonly used when designing 2D games within Unity and setting up an orthographic camera is pretty simple:

Step 1 : Set position to x=0, y=0 and z = -10 (any depth that you choose depending on the Z values of your game objects).

Step 2 : Rotation to x=0, y=0 and z=0

Step 3 : Scale to x=1, y=1 and z=1

Step 4 : Change the ‘Projection’ drop-down to Orthographic (default is Perspective).

Step 5 : Set Camera size to 5 (this number can vary – with my game resolution a size of 5 worked).

Step 6 : Create some objects (I added three simple cubes) and change Ambient Light to light grey via Edit > Render Settings > Inspector > Ambient Light (colour chooser).  You can use any light colour or if you prefer stick to the  default black ambient light and add some lights to the scene.

What You Should Be Seeing
What You Should Be Seeing

References

  1. Overview of the Camera Class – Unity 3D Documentation
  2. Detail on the Orthographic Camera – Unity 3D Documentation

Tip : Designing an Isometric Game in Unity3D

The idea of isometric art in video games is normally to make a 2D game look 3D, a lot of effort goes into making this work and look right.

Our friend Unity3D helps us out a lot here, to setup an isometric game all we need to do is adjust the Main Camera settings to give us a isometric view of our scene.

Step 1: Select Main Camera from the hierarchy

Step 2: Within the Inspector and under the Transform tab change the Main Camera’s position as follows : x = -10, y = 15, z – 10

Step 3: Within the Transform tab change the Main Camera’s rotation as follows: x = 30, y = 45, z= 0

Step 4: Under the Camera tab select ‘Orthographic’ from the Projection drop-down menu, which is normally set to ‘Perspective’ as default.

Check Your Work: With a few object in your scene you will see them displayed in the Isometric style within the Game View.

Your settings should look the same as below (Unity 4.1.5):

Isometric Camera Settings
Isometric Camera Settings

Let’s Get This Started!

I am standing at the foot of Mount Ultimate Challenge and wondering where to start!

I have been reading up on game development and trying to select the tools that will help me design on the Ouya. After much investigation and reflection I have decided to learn the Unity 3D platform as its one powerful beast, has a excellent community, good tutorials and its scalable for small and big projects.

It provides me with another dilemma of which programming language to concentration on learning – in the end I decided on UnityScript (JavaScript pretty much) as its slightly familiar to me and seems to be easier for me to follow.

I have also downloaded Blender as it’s free, has a vibrant community online but also powerful enough to take care of all of my modelling needs.

Now I need some tutorials to get stuck into to understand Unity 3D a little more!