Home Game Development Building an FPS Game with Unity

Building an FPS Game with Unity

books-svg-icon Book
eBook $39.99 $27.98
Print $48.99
Subscription $15.99 $10 p/m for three months
$10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
BUY NOW $10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
eBook $39.99 $27.98
Print $48.99
Subscription $15.99 $10 p/m for three months
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
  1. Free Chapter
    Getting Started on an FPS
About this book
Publication date:
October 2015
Publisher
Packt
Pages
326
ISBN
9781782174806

 

Chapter 1. Getting Started on an FPS

Welcome to Building an FPS Game with Unity! This chapter is dedicated to offer a brief overview, from a beginner's point of view, of the exciting world of Unity development for the creation of a First Person Shooter (FPS) title, leveraging the powerful Ultimate First Person Shooter (UFPS) framework by VisionPunk and Prototype/ProBuilder 2.0 by ProCore3D. But, before we get started, we first need to get all of the resources we'll need and set up our project for success.

Over the course of this book, we will be creating a 3D FPS game similar to the popular games in the market such as Call of Duty: Black Ops III and Halo 5: Guardians.

We will learn how we can create custom weapons of our own as well as how we can create interior and exterior environments. After creating our environments, we will populate them with different combat encounters for players to fight as well as include intractable objects such as exploding barrels. We'll then customize our user interface using Unity's new GUI system before we package our game and create an installer to get the game out into the world!

This project will be split into a number of tasks. It will be a simple step-by-step process from the beginning to the end. Here is the outline of our tasks:

  • Project creation

  • Getting started with Unity's Asset Store

  • Installing UFPS

  • Installing Prototype

  • File organization

  • Customizing Unity's layout

 

Prerequisites


Before we start, we will need to get the latest Unity version. You can always download it from http://unity3d.com/unity/download/. At the time of writing this book, the page looks like this:

Once you get to this page, click on the CHOOSE YOUR UNITY + DOWNLOAD button (this page onward, I will be using the PERSONAL EDITION version). Then, click on the DOWNLOAD INSTALLER option.

The download assistant should be installed from your default downloads directory. Once it is installed, double-click on the file to open it.

Once there, go through the installation using the default properties. At the time of writing, we are using Unity 5.0.0f4, but most things should work with minimal changes but be sure to check out the book's website to check for any errata.

Since it needs to download Unity, this process may take some time.

 

Project creation


At this point, I assume that you have freshly installed Unity and have started it up. Follow these steps to create a new project in Unity:

  1. With Unity started, go to New Project. Enter a Project Name value such as FPS Game - Chapter 1 as that's what we are making and the chapter we're making it for, or whatever you want to call your project. Select Location of your choice somewhere on your hard drive and ensure that you have your game set to 3D. Once completed, select Create project. At this point, we do not need to import any packages as we'll be doing it manually.

  2. Here on, if you see the Welcome to Unity pop up, feel free to close it as we won't be using it. At this point, you will be brought to the general Unity layout, which should look as follows:

Note

I'm assuming you have some familiarity with Unity before you read this book. If you want more information on the interface, please visit http://docs.unity3d.com/Documentation/Manual/LearningtheInterface.html.

 

Getting started with the Asset Store


Since Unity 3, the Asset Store has been similar to Apple's/Android's app stores, except, instead of apps, you can buy prebuilt assets that can be imported directly into your project. We will be using this in our project; but, before we do so, we will need to have an account, that can be created using the following steps:

  1. To open the Asset Store via Unity, we can go to Window | Asset Store from the top toolbar.

    Note

    You may also open the panel by pressing Ctrl + 9 (command + 9 on Mac). If nothing happens, make sure Unity is focused on window by clicking on the program and trying again. If you prefer working outside Unity, you may also go to the Asset Store website at https://www.assetstore.unity3d.com/. However, you'll need to download assets from Unity via the Download Manager, which you can learn about from the link given later in this chapter.

  2. Next, go to the top-right corner of the panel and click on the Create Account button. Fill out your information and click on Create account at the bottom of the screen.

  3. You should receive an activation e-mail shortly after you submit the form. Open it and click on the activation link provided to verify your account.

  4. Once this is done, go to Log In from the top-right corner of the panel and enter the information you put in when you created the account. If all goes well, the top-right corner of the window will change to reflect that you are logged in.

With this, we can download and purchase assets from the Asset Store!

Note

Do not be concerned if you do not see 11 by your account, it just shows that I have a Unity Pro account.

For more information on the Asset Store and how to navigate using it, visit http://docs.unity3d.com/Manual/AccessNavigation.html.

Installing UFPS

Creating a game completely from scratch takes a considerable amount of time. Creating a first-person shooter relies on having a lot of knowledge as well as problem solving with things such as physics, mathematics, graphics, and programming. Now, books of each of these subjects could have been written based on it; but we are assuming that you want results in the fastest amount of time possible.

Rather than taking the tens of thousands of hours it would take to create it from scratch, we will leverage the very popular Unity add-on UFPS (Ultimate FPS) from VisionPunk. It will give us a solid foundation to create our own project with hundreds of parameters, which we can customize to create a project exactly the way we want it to be.

It's important to note that UFPS does cost money. But considering that a solid game programmer generally makes $50 or more an hour, the amount of time saved really makes it a worthwhile investment.

Now that we are logged into the Asset Store, let's purchase and install UFPS:

  1. Now, from the search bar directly below the login information, search for UFPS. You should see an icon that looks similar to the following:

  2. Click on the first option, which will bring you to the following page:

  3. Now, click on the Buy button and purchase the asset. Once it is purchased, the screen will change the Buy button to a Download button. You can click on it to download the asset and bring it into your project.

  4. Once it is downloaded, an Importing package window will open, giving you the option to choose which parts of the package you wish to import. We want everything, so just click on the Import button.

    Note

    If, for some reason, you get an error (the bottom bar, or Console, in the Unity interface) while importing that says something like 'Fatal error! getManagerFromContext:…". This is a bug in Unity due to the large file size UFPS has. Just Quit and continue with the import once again, when you restart Unity.

  5. Once the project is imported, close the Asset Store window and go back into the Unity Editor. From there, go down to the Project tab in the bottom-left corner of the screen and double-click on the UFPS folder. Go to Base\Content\Levels\SkyCity and double-click on the SkyCity file to open an example level. Then, press the Play button at the top-center of the project to start the project!

With this, we know that UFPS is installed correctly!

 

Installing Prototype


In general, creating levels in Unity is a painful experience. You have to type in the values for each piece that you want to add or you have to create everything inside a modeling program and import it, which will require you to have 3D modeling skills.

Other game engines have tools like Binary Space Partitioning (BSP) or Constructive Solid Geometry (CSG), which allow you to build geometry from scratch and apply materials to it to create areas for play. Filling in the gap that Unity has, ProCore3D has created a toolkit that allows for in-editor construction.

We will later on use ProBuilder to polish up our final product; but, in the meantime, we will use Prototype, their free version to build the basic structure and flow of our levels without wasting time, thus making things visually appealing until we polish it. Perform the following steps to install Prototype:

  1. Open the Asset Store once again by going to the toolbar, searching for Prototype, and looking for the following icon:

  2. Click on the first option in the top-left corner and you should be brought to a page like the following one:

    Tip

    After the writing of this book, Prototype will in the near future be replaced by ProBuilder Basic which is still 100% free but has additional features. I've talked with the creators about this, and they've confirmed with me after reading the book that everything discussed here should still work with the new version. For more information on this, check out http://www.protoolsforunity3d.com/probuilder/.

  3. Click on the Download button and wait for it to finish. Then, import the entire package by clicking on Import.

  4. We will now test it out to see whether everything is imported correctly. Create a new scene inside Unity by going to File | New Scene. Once there, press Ctrl + K to create a new cube using Prototype.

With this, we know that it was installed correctly! It may look pretty simple now, but we will be diving even more into using these tools later on.

Note

For more information on Prototype, check out http://www.protoolsforunity3d.com/prototype/.

 

File organization


Keeping your Unity project organized is incredibly important. As your project moves from a small prototype to a full game, more and more files will be introduced to your project. If you don't start organizing it from the beginning and keep planning to tidy it up later on, things may get quite out of hand as the deadlines keep coming.

Setting up a project structure at the start and sticking to it will save you countless minutes in the long run. It will only take a few seconds and is what we'll be doing now.

  1. Go to the Assets folder from the Project tab in the bottom-left corner of the screen. Once there, click on the Create drop-down menu. Click on Folder and you'll notice that a new folder has been created inside your Assets folder.

    Tip

    Similarly, you can right-click on the negative space within the Project window to create a folder.

  2. After the folder is created, you can type in the name of your folder. Once it is named, press Enter. Let's now create a folder called MyGame. We also need to create folders for the following directories inside the MyGame folder:

    • Prefabs

    • Scenes

    • Scripts

Note

If you happen to create a folder inside another folder, you can simply drag and drop it from the left toolbar. If you need to rename a folder, just simply click on it once and wait, you'll be able to edit it again. Alternatively, on the keyboard you can press F2.

Your project should now look like this:

 

Customizing Unity's layout


While working with Unity in this book, I will mostly be using its default layout. If, for some reason, your layout does not look like the earlier screenshot, you can reset it by going to the top-right corner of the window and selecting Layout | Default.

You can customize the layout by clicking and dragging any tab to wherever you want it to be. There are also additional options such as making the Project tab use a one-column layout by right-clicking on the tab and selecting One Column Layout. Sometimes, I like to split the center with the Scene tab on one side and the Game tab on the other, so I can see how things change from a different angle. For those of you with multiple monitors, you may use a monitor just for the game. It's all up to your preferences, but keep your changes in mind, as I'll assume that you'll be using Default.

Note

For more information on customizing your Unity layout, check out http://docs.unity3d.com/Manual/CustomizingYourWorkspace.html.

 

Summary


Hopefully, you've enjoyed taking the first few steps toward becoming an FPS game developer with Unity! In this chapter, we learned how to create a project inside Unity 5. We then learned how to create an account and navigate the Unity Asset Store. After this, we learned about UFPS and Prototype and installed them. Finally, we touched upon file organization and customized Unity's layout.

In the next chapter, we will delve deeper into using Unity Editor and UFPS by creating our own custom weapons!

Latest Reviews (13 reviews total)
bought loads of unity 5 books from here very informative
The content is perpetually out of date, but still mostly usable.
Building an FPS Game with Unity
Unlock this book and the full library FREE for 7 days
Start now