Unity Basics: Camera Controls & Simple Prototyping

integerman

Matt Eland

Posted on January 20, 2023

Unity Basics: Camera Controls & Simple Prototyping

Let’s walk through the basics of working with the Unity editor to build a small environment. We’ll cover the scene view, controlling the user interface, positioning cameras in your game world, and creating some simple 3D objects for prototyping.

This article’s content is also available via a YouTube video:

This article assumes you have Unity installed and a 3D project already created with an empty scene.

See my article on creating a new Unity project for more details and how to choose a correct template for your needs.

Controlling the Unity Editor Scene View

Unity projects are structured around scenes, which are a collection of game objects arranged in a way to represent a part (or the whole) of your game world.

The Unity editor is always open to one scene in your project, which is shown in the scene view pictured below:

Unity Scene View

The scene view has a few key components:

  • The main scene view showing a 3D view of the game world. This is located in the middle by default.
  • A hierarchy of game objects present in the scene, in the left position by default.
  • An inspector allowing you to see more details on the currently selected game object. This starts docked to the right.

In this article we’ll primarily be focused on the central scene view, though we’ll point out a few topics of interest with the Hierarchy and Inspector as well.

Creating a simple 3D object will help us make sense of the game world more, so let’s do that now.

Creating Primitive Shapes in Unity

The scene view starts with very few objects inside of it and you’ll want to add some new objects to your scene.

Let’s explore adding simple shapes to your game world by using the built-in primitive shapes.

There are two good ways of adding a shape to your game world:

First, you can right click on the back of the hierarchy view and choose 3D Object and then the specific object you want to create.

Context Menu to add a Plane

Alternatively, the Game Object top-level menu will let you create objects by selecting 3D Object and then the object to create.

Whichever way you’d like, create a new Plane to serve as the ground. The plane object should now be created in the center of your game view.

Using the Unity Editor Inspector

Once you have your new plane created, click on it in the scene view or in the hierarchy. It should now appear selected in the hierarchy, scene view, and be featured in the inspector as pictured below:

The Unity Editor Inspector View

The inspector will always show details on the currently selected game object.

Specifically, the inspector will list the various components that are attached to the game object you have selected.

Components accomplish a very specific game function and there are a lot of components out there, from mesh renderers that make the object appear to the player to colliders that control collision detection to even custom things like custom scripts you can author and add to any game object you’d like.

Every game object also has a transform associated with it which tells us where in the game world that object is located.

In this case, your plane is somewhat small, so we can modify the Scale X and Z properties to be 10 each.

A larger plane

If you’d prefer a more interactive way of resizing the plane, the scene view has some modes that will help you with that as we’ll see next.

Controlling the Scene Perspective in Unity

In a complex scene, there will be many different objects in the scene and you’ll need to be able to move your perspective around the scene to work effectively.

While you can navigate through the scene in most modes, it is probably best to click on the “hand” icon or press the Q key on your keyboard to move into panning mode.

The Pan Control

Once you do this, left clicking into the Unity Editor and dragging the mouse will pan your view around horizontally and vertically relative to where you were looking. Holding down shift while panning like this increases the rate at which you pan.

If you instead drag with the right mouse button, you’ll find yourself looking in a different direction.

Panning the Scene View

The mouse wheel will zoom you in and out of the current view.

Single clicking on an object in your view will center it in your screen.

Once you have an object selected, holding down alt and using the left mouse button will allow you to orbit the object in your field of view.

To demonstrate this, add a new 3D Object of type Cylinder to your game world, then select it and use alt and left mouse button to orbit around it.

Adding a Cylinder and Orbiting it

Manipulating Objects in the Scene View

The Unity editor offers a few different ways of manipulating the current object in scene view. These modes are represented with the following buttons:

Scene Controls

These buttons are:

  • Pan (Q hotkey) allows you to move the scene perspective without danger of altering the scene
  • Move (W) allows you to move the selected object(s) in the game world along one or more axes.
  • Rotate (E) Allows you to rotate the object along one or more axes
  • Scale (R) Allows you to stretch or shrink the object along one or more axes
  • RectTransform (T) Allows the object to be resized using rectangle handles
  • Transform (Y) Allows for easy rotation and movement from a single view

The most critical tools to work with are the move, rotate, and scale tools, so let’s use each one to add walls to our game world.

Moving Objects with the Move Tool

While you can use the inspector to move any object, it’s often more intuitive to use the move tool. Let’s take a look at how this works.

First, create a new 3D Object of type Cube following the steps listed above.

Note: the cube may intersect with the cylinder initially. That’s fine.

Next, switch to move mode by clicking on the move icon in the scene view or pressing the W key.

Next, click and drag on a shape handle to move the cube along one axis to the edge of the plane as shown below:

Moving Objects

Finally, take a look at your transform view and even out the X, Y, and Z positions using rounding. I wound up putting my cube at 3.5, 0.5, -50 for its position.

Note: you can get around some of this imprecise movement by holding control when moving an object to have it snap to major gridlines.

Scaling Objects with the Scale Tool

Let’s scale the wall out horizontally to reach the full width of the plane.

First switch to the scale tool by clicking its icon or pressing the R key.

Next, click and drag the shape handle to resize the shape along that axis. You may need to zoom out or pan to adequately accomplish this.

Additionally, if your cube was not perfectly centered you may need to switch back to the move tool to relocate it.

Scaling Objects

Feel free to also scale your wall vertically for better effect.

Finally, round out any values in your inspector for the cube. Mine would up having a scale of 100, 5, 1 and a final position of 0.5, 2.5, -50.

Duplicating Objects

Our wall is fine for a prototype, but it’s only on one side of the plane. Let’s fix that by adding another wall opposite this one.

To duplicate an object, first select it in the hierarchy view. Next, press Control + D to duplicate that object.

Note: alternatively, you can copy and paste the object to get the same effect

This created a new wall object on the exact same location as the other wall.

Switch back to the move tool to move the wall across to the other side of the plane.

Duplicating and Moving

Rotating Objects

Before we move on from our new shape, we should probably rotate it 180 degrees to face inwards towards the center of the floor. This will make our job easier for texturing later on to have all walls facing the same direction.

Select the new wall and click the rotate button or press the E key.

Next, hold control and drag along the green Y axis to rotate the wall cleanly to 180 degrees on that rotational axis.

Rotating a Wall

Once this is done, we have two good walls and two missing walls.

Let’s fix this by selecting both walls by holding the control key and clicking both of the walls in the hierarchy until they’re both selected.

Next, press control + D to duplicate that set of walls.

Finally, switch to rotate mode by pressing E and then control and drag along the y axis to rotate the walls 90 degrees to be on opposite sides of the plane as shown below.

Cloning and Rotating

This is by no means a perfect room, but this is a good enough room for us to use as a testing area in future pieces of content.

Adjusting the Game Camera

Before we end the article, we should do something with the game camera.

Right now, if you run the game you’ll see something like this:

Default View

This is fine if you’re making a first-person shooter, but this article is actually the basis for a series of future articles about building a top-down game, so we’ll want a top-down perspective instead.

Unity renders the game view via the Main Camera object by default. In order to change the player’s perspective, you can select the Main Camera object and move and rotate it as needed to frame your shot as shown below:

Moving the Camera

This can be a little tedious, so I’ve taken to doing something different instead.

Instead of moving the game camera, I use the pan, tilt, and orbit controls to manipulate the scene’s perspective until it resembles what I want for my game camera.

Next, I click on the main camera, select the Game Object menu and then the Align With View option.

Aligning with the Camera's View

What’s Next?

And there we go. This was not a lot of work to learn the Unity user interface while creating a simple test room for prototyping a game later on.

This article represents the first in a series of articles I plan on writing about prototyping a top-down action game over the coming year, so stay tuned for more content on that project.

In the meantime, please let me know what you’re interested in with Unity game development and how I can help you on your journey.

💖 💪 🙅 🚩
integerman
Matt Eland

Posted on January 20, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related