VG1, Quest 1 - Movement

Download Files

Supporting files for VG1 quests are part of a single archive that you can download here.

Create Project

*Your Unity version may differ from what is pictured. You MUST use the Unity version required by the instructor for your particular course semester.

From Unity Hub, click "New project".

You will use this one project for MULTIPLE solo assignments throughout the entire semester. Replace my name with your own last name and first name. You will have a second separate project for your semester project.

Replace my name with your own last name and first name.

Unity provides different templates for starting your project. All of the projects we do this first semester will be 2D games.

Give Unity some time to prepare the new project. The full Unity Editor interface will automatically open once the project is ready.

Set-Up Folders

The Project tab portrays your file system and the assets that are within your project. You should always keep your projects organized with an appropriate folder structure. Clicking the + lets you create new assets including folders.

Because all of your assignments will share this one project, we will use folders to help organize content from different exercises. Create the folder structure portrayed in this image.

Import Files

You can drag-and-drop files into the Project tab to include them in your game. Add the q1_char.png from the Course Files to your project.

A texture is a visual graphic that can be applied to some aspect of your game to be shown on screen.

Graphics Import Settings

The Inspector tab is a contextual tool for examining and configuring elements of your game. Clicking different assets will show you different configuration options for that particular content.

Click your q1_char in the Project tab and match these settings for your newly imported video game graphic using the Inspector tab.

We will keep most of the default settings but will specifically change the Pixels Per Unit and Compression. A Pixels Per Unit (PPU) of 512 means we will fit 512 pixels per grid unit in our game’s coordinate system. It ensures graphics are properly sized when they are brought into the game. Setting the Compression to None will keep our graphics at full quality.

Rename Your Scene

To keep our project organized for the semester, we will rename our current scene to Q1 to represent this assignment.

Find your Scene in the Project->Assets->Scenes folder and rename SampleScene to Q1.

You may be asked to reload the currently active scene.

Create a GameObject

In Unity, nearly everything that appears in a game is “GameObject.” GameObjects are the fundamental building blocks of games in the Unity Engine.

While the Project tab shows you what assets are in your project, the Hierarchy tab shows you what GameObjects are in your Scene. A Scene is what is currently portrayed by your game. Like a movie, a game will progress through multiple Scenes, and you can use Scenes to organize your experience into different levels, screens, etc.

Right now, our Q1 Scene only has the default Camera that allows the engine to “see” the game.

You can use the + to create an empty “blank” GameObject for us to configure.

Notice how it gives you the opportunity to rename the GameObject. Change the GameObject’s name to Character. We will eventually make this character move around in response to keyboard input.

When you select Character in the Hierarchy tab, notice that the Inspector tab changes to describe that GameObject.

When you Inspect a GameObject, you will see that GameObject’s list of Components. While GameObjects are the fundamental building blocks of the Unity Engine, Components are what define any GameObject. A GameObject is not a "Character" because we named it that, but rather because we attach specific Components that describe what a Character is.

Switch to the Move tool and look at the Scene tab.

Notice that without any Components besides the Transform Component, our Character GameObject simply exists at Position 0, 0, 0 somewhere in the game Scene. It has no graphics or any other substance.

Add a SpriteRenderer Component

Our "Character" should have a graphic. Rendering graphics is a functionality gained by having a specific kind of Component attached to our GameObject.

Specifically, the SpriteRenderer Component allows a GameObject to have 2D graphics. Attach one using the Add Component button.

Configure SpriteRenderer Component

The Inspector will let us configure this SpriteRenderer Component.

In the Sprite property, you can drag-and-drop the spaceship graphic from the Project tab into the Sprite blank in the Inspector tab. The other default settings should be fine.

Our Character now has a graphic!

Organize More Folders

We will keep all of our C# code in dedicated folders for each exercise.

Create a C# File

Create a C# file, which we will use as a “Behavior Script.” (C# is not technically a scripting language, but because C# replaced Boo and UnityScript in the engine, the terminology is still commonly used to describe programming in Unity. GameObjects are also like actors who follow a "script" programmed in C# for their behaviors.)

Whenever you create a C# file through Unity, it will automatically generate a code template based on the name you provide. In Unity, the filename must ALWAYS match the C# Class name inside the file. If you ever mistype or rename your files, you must also rename the C# Class inside the code. (This also means no spaces or other invalid characters can be used in these filenames.)

Notice how the filename exactly matches the class name. Because we will be creating multiple assignments within the same project, we will always use namespaces to isolate the code between assignments.

If you mistyped the file name, Unity will generate C# code matching that wrong name. When you correct the filename, you must also correct the text of the class declaration inside the file.

Attach the C# Behavior as a Component

In the Inspector when your Character GameObject is selected, click the "Add Component" button to search for and add UFOController. (You can also drag-and-drop the UFOController file from the Project tab onto the "Add Component" button in the Inspector tab.)

If your code's class declaration does not match the filename, you will receive an error similar to what is shown below. As the error suggests, fix this by making the names match.

Whatever approach you use, your Behavior Script will now appear as a Component on the GameObject. Any Component you program can be just as functional as any of the Components that come built-in with the Unity engine.

Program Basic Movement

As a "Hello World" exercise, our goal is simply to get a character to appear on the screen and move in response to player input. We will use the Arrow Keys to do this.

Much of this code may be unfamiliar to you right now, but we will explore all of it more in-depth during class discussion.

If your C# file doesn’t open as expected, check your "Unity > Preferences" ("Edit > Preferences" on Windows) and make sure your code editor of choice is selected under External Tools. The actual "External Script Editor" may differ based on what you have installed on your computer.

Playtest

Consumer and professional attitudes toward software quality assurance testing are an ongoing source of conflict and controversy within the game industry. Harassment and lawsuits abound from misunderstanding and neglect of this critical process.

Testing is just as important a part of the game creation process as any other activity. It should always be a part of YOUR process in this class.

ALWAYS remember to SAVE AND TEST your work before submission. Playtest frequently as you progress through your exercises to check for both expected and unexpected behavior in your projects. If you only check for things that work, you may miss what is broken. What you submit is what is what we grade. We cannot grade unsubmitted work sitting on your hard drive. You will not receive credit for missing, non-functional, inaccessible, or unplayable work.

Click the Play button to test your game. Your character should move in the matching direction of each of the four arrow keys when pressed. You may notice that on faster computers, the character moves too fast to be controllable. We will learn how to fix this bug in the next assignment.

Pay attention to the bottom-left corner of the Unity Editor window for any Red Errors. You can view more details by opening up Window > General > Console. If your work generates Red Errors, your assignment must be fixed before submission. Testing your work is your responsibility. It is not the job of the instructor or teaching assistants to find red errors for you. Red Errors are critical errors and represent a compilation failure or a video game crash. It is unacceptable to ever ship your software in such a broken state. Unwareness is not an excuse, but rather a failure to engage in the required quality assurance process.

On occasion, internal Unity tools may generate a red error due to beta software, network errors, tool misconfiguration, or other debugging situations. These errors are of a slightly different nature and occur during editor debug time rather than compilation time or runtime, and would not affect the execution of a game for a customer. You will NOT be penalized for editor errors that do not originate from your own work. It can be difficult for newcomers to distinguish between editor errors and your own programmer errors, so if you’re ever unsure how to fix a red error, just ask. Otherwise, always assume full responsibility for fixing your projects and do not get in the habit of blaming the tools, which is a very common crutch of inexperienced game developers. This screenshot shows an example critical red error at compile time which prevents the game from running in the first place:

This screenshot shows an example of a critical red error at execution time which would cause the game to crash if it were exported for consumers:

Submit Assignment

SAVE any open files or scenes.

Submit your assignment for grading following the instructions supplied for your particular classroom.