Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Mastering Unity 5.x
Mastering Unity 5.x

Mastering Unity 5.x: Create amazing games with brilliant game play features using Unity 5.x

eBook
€22.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Mastering Unity 5.x

Chapter 2. Level Design and Structure

This chapter is about designing and building playable levels for Dead Keys. More accurately, Dead Keys consists of multiple levels, and our focus in this chapter will be on the creation of one of those levels in detail. Only one needs be considered because the level-creation process is merely repeated creatively, after creating the first level, to produce all remaining levels at increasing difficulty levels. By level, I mean a scene in Unity terms-a complete and integrated 3D world where the game evolves according to its internal rules and logic. We'll look in depth at using and reusing modular assets, such as environment meshes, to build interesting levels of any size needed; we'll also see lightmapping and lighting overall to enhance realism, as well as NavMesh generation for artificial intelligence and Occlusion Culling for rendering optimization, among other issues. By the end of this chapter, we'll have constructed an integrated...

Setting the scene with a skybox

Our game environment should be dark, creepy, and suspenseful. But, every new Unity scene is created with a default, procedural skybox representing a cheery daytime, exterior. This needs to be changed. A skybox is ultimately a cube with flipped normals that surround and encompass the environment. Its faces contain an environment texture which, when mapped correctly, appears seamlessly across the model, creating the look of a vast skyline surrounding the scene. The primary purpose of our skybox should be to set a base and ambient lighting. The most appropriate skybox for our usage, then, is a night skybox or, at least, a dark, stormy (and perhaps slightly alien) skybox. There are many ways in Unity to create a skybox. One method is to create a cube-map texture (six separate textures) inside the image-editing software that maps to the faces of a cube. Another method, available in Unity 5, is a procedural skybox. Using this, Unity generates a skybox from some...

Level building - modular construction sets

Now the fun begins, though logistically challenging, the process of level building. Our aim is to build a fun and interesting level. But this must be balanced against many factors, including level size, ease of navigation, variety, and more. Creating a level is challenging because misplaced or poorly designed elements stand out for their failings. They break the player's experience. Decisions about architecture and where to include straight sections, turns, jumps, ledges, props, and doors collectively influence the atmosphere and mood of a level. Here, we'll focus on the modular building method, piecing together an expansive level from reusable pieces, exploring reasons, and justifications for our choices along the way. However, let's first see the modular set in its entirety, that is, the complete collection of architectural meshes from which the level must be constructed.

Level building - modular construction sets

Modular set for level construction

Each mesh is a modular...

Level building - organization and structure

Let's start the level construction process. There are many ways to begin here, but it's a good idea from the outset to develop with a clean workflow in mind. By clean I mean an organized, structured, and easy-to-maintain workflow; one that remains maintainable for projects of many scales. First, delete any and all objects in the new scene, and then create a single empty GameObject named root by navigating to GameObject | Create Empty from the application menu. This object will be the top-most object in the hierarchy, from which everything else will be a child directly or indirectly.

Level building - organization and structure

Creating a root object for the scene

Next, create a new child object named env, which will contain all environment pieces. Make sure that both the root and env objects are positioned at the world origin at (0,0,0). I typically position the world floor at 0 on the y axis, making this the lowest point in the world. It is, of course, possible for objects...

Level design - tips and tricks

Don't underestimate the design challenges faced when building a level. Arranging mesh modules meaningfully and constructing a layout that encourages exploration and invites interest is challenging. Is a corridor too long or too bendy? Is a walkway too narrow or too wide? Should there be a prop (such as a chair or a desk) in the corner of a room? These types of questions, and others, matter! They're not the kinds of things that should be settled just by flipping a coin. Consider the following design tips and tricks; that is, some guiding principles intended to help you build more interesting levels faster and easier.

Objective and feedback

Always remember the player objective when designing-the goal to be reached by the player during gameplay. This may be reaching a specific location, defeating a specific enemy, achieving a financial target, or something else. Most players like to feel successful, like to feel like they're moving toward that goal...

Setting the scene with a skybox


Our game environment should be dark, creepy, and suspenseful. But, every new Unity scene is created with a default, procedural skybox representing a cheery daytime, exterior. This needs to be changed. A skybox is ultimately a cube with flipped normals that surround and encompass the environment. Its faces contain an environment texture which, when mapped correctly, appears seamlessly across the model, creating the look of a vast skyline surrounding the scene. The primary purpose of our skybox should be to set a base and ambient lighting. The most appropriate skybox for our usage, then, is a night skybox or, at least, a dark, stormy (and perhaps slightly alien) skybox. There are many ways in Unity to create a skybox. One method is to create a cube-map texture (six separate textures) inside the image-editing software that maps to the faces of a cube. Another method, available in Unity 5, is a procedural skybox. Using this, Unity generates a skybox from some...

Level building - modular construction sets


Now the fun begins, though logistically challenging, the process of level building. Our aim is to build a fun and interesting level. But this must be balanced against many factors, including level size, ease of navigation, variety, and more. Creating a level is challenging because misplaced or poorly designed elements stand out for their failings. They break the player's experience. Decisions about architecture and where to include straight sections, turns, jumps, ledges, props, and doors collectively influence the atmosphere and mood of a level. Here, we'll focus on the modular building method, piecing together an expansive level from reusable pieces, exploring reasons, and justifications for our choices along the way. However, let's first see the modular set in its entirety, that is, the complete collection of architectural meshes from which the level must be constructed.

Modular set for level construction

Each mesh is a modular piece (or module...

Level building - organization and structure


Let's start the level construction process. There are many ways to begin here, but it's a good idea from the outset to develop with a clean workflow in mind. By clean I mean an organized, structured, and easy-to-maintain workflow; one that remains maintainable for projects of many scales. First, delete any and all objects in the new scene, and then create a single empty GameObject named root by navigating to GameObject | Create Empty from the application menu. This object will be the top-most object in the hierarchy, from which everything else will be a child directly or indirectly.

Creating a root object for the scene

Next, create a new child object named env, which will contain all environment pieces. Make sure that both the root and env objects are positioned at the world origin at (0,0,0). I typically position the world floor at 0 on the y axis, making this the lowest point in the world. It is, of course, possible for objects to fall below...

Level design - tips and tricks


Don't underestimate the design challenges faced when building a level. Arranging mesh modules meaningfully and constructing a layout that encourages exploration and invites interest is challenging. Is a corridor too long or too bendy? Is a walkway too narrow or too wide? Should there be a prop (such as a chair or a desk) in the corner of a room? These types of questions, and others, matter! They're not the kinds of things that should be settled just by flipping a coin. Consider the following design tips and tricks; that is, some guiding principles intended to help you build more interesting levels faster and easier.

Objective and feedback

Always remember the player objective when designing-the goal to be reached by the player during gameplay. This may be reaching a specific location, defeating a specific enemy, achieving a financial target, or something else. Most players like to feel successful, like to feel like they're moving toward that goal. During gameplay...

Level lighting - preparation


Reaching this far you've now made a complete scene in terms of meshes representing the first level, composed from modular environment pieces (corridor sections). Presently, the level features no lighting, navigation meshes, music or audio, and Occlusion Data; but, we'll add these soon. Let's start with lighting. In Unity, there are three main lighting types or systems, which exist on a spectrum:

  • Baked lighting

  • Real-time lighting

  • Precomputed global illumination

These are discussed in detail further here.

Baked lighting

Baked lighting is the optimal lighting method, but it can only be used under specific circumstances. With Baked lighting, all lighting data (highlights, shadows, and so on) are precalculated and saved to a texture (lightmap). The lightmap is then applied to scene geometry using a second UV channel (Lightmap UVs), on top of their standard materials, using multiplicative blending. This makes geometry appear illuminated by scene lights. This approach...

Getting started with lightmapping


To start Baking Scene lighting, we'll first need to activate Lightmap UVs for the environment meshes and then position some lights in the scene where appropriate. To activate Lightmap UVs, select all environment meshes in the Project panel and enable Generate Lightmap UV from the object Inspector. Then click on Apply. This method is useful for generating a second UV channel when one doesn't already exist. This defines how lighting is baked to the lightmap texture. Unity applies an auto-unwrap projection using settings from the Advanced roll out. If, by contrast, your own meshes already have a custom, second channel, then you can use this channel instead for Lightmap UVs simply by disabling Generate Lightmap UVs.

Configuring Lightmap UVs

Note

For meshes with two UV channels, you can enable Swap UVs from the object Inspector to switch channel order, if needed. This makes the second channel the primary, and the first channel the secondary. The primary channel...

Baking lightmaps - resolution and size


Our scene now features marked static objects, complete with Lightmap UVs, and is ready for lightmapping. The default settings for all Unity scenes and projects is not compatible with a full lightmap setup as we require, and so we must access the lighting settings. To do this, display the Lighting window by navigating to Window | Lighting from the application menu. Once opened, dock the free-floating window into the object Inspector as a separate tab. This is convenient because we can view the lighting settings and inspect the Scene viewport side by side.

Accessing the Lighting window

First, let's disable all precomputed GI settings, by removing the check mark from the Precomputed Realtime GI rollout in the Lighting window. This completely deactivates real-time GI for the scene. In addition, specify the night time skybox (created earlier) for the Skybox field. This is important for establishing a base, ambient lighting pervading the scene, even in the...

Baking lightmaps - details


Having now established a resolution and Atlas Size, we should specify baking details to improve the quality and appearance of our lightmaps. To do this, enable Ambient Occlusion and tweak the Max Distance field until you get the volumetric effect desired. This requires rebaking. Ambient Occlusion is sometimes called Contact Shadows because it generates shadows where two or more solid bodies meet, such as the floor meeting the wall, or crevices and cracks. This creates a volume effect, enhancing the 3D-feel of a scene.

Enabling Ambient Occlusion

In addition, enable Final Gather. Set the Ray Count to 256. Final Gather reduces noise and improves the quality of lightmapping. Higher values result in smooth, higher quality output, at the expense of the calculation time.

Enabling Final Gather

Finally, you can increase the resolution of specific objects, if needed. We don't need this for DK, but if you have large, eye catching and very important objects in a scene (such...

Light Probes


The lightmap setup works well for the scene, but applies only to static objects; such as walls, floors, ceilings, and props. Animated and movable objects, such as NPCs, will by contrast continue to be illuminated by expensive dynamic lights, unless additional steps are taken. Let's take those now using Light Probes. They are special sampling objects, which should be positioned strategically around the scene to record an average of light color and intensity at that location. When multiple Light Probes exist, movable objects such as characters are illuminated by interpolated values taken from the nearest probes. Light Probes, therefore, record color and intensity, but they do not cast shadows. To get started with Light Probes, create a new game object to act as the parent of all probes. Navigate to GameObject | Create Empty from the application menu. Name this object LightProbes.

Creating an empty object for Light Probes

Next, add a Light Probe group component to the newly created...

Lighting FAQ


This section takes time out to explore lighting issues and problems that sometimes arise and common methods for resolving them. The issues listed here may not arise for the Dead Keys project specifically, but it's likely you'll encounter them somewhere, on some projects. Consequently, it's good to know how the issues are solved or at least avoided. This section takes a Question and Answer format:

  • Scene lighting appears wrong when opening a scene in the editor: This happens when Auto is enabled from the Lighting window. As the scene is opened, lighting is rebaked. This may take time or may fail entirely. The result is that scene lighting may not appear correct instantly when a scene is opened. You can resolve this by disabling auto baking from the Lighting window and then saving the scene to confirm the change. The next time the scene is opened, the existing baked data will be used instead.

Disabling Auto for baking

  • Scene lighting is baked, but appears messed up in the scene...

Navigation mesh


Now it's time to explore NPC intelligence and, specifically, path finding. We'll need our NPC zombies to move around the scene intelligently; that is, to move without bumping into walls, floors, doors, and other obstacles, and without taking the most complex routes to nearby destinations. Our zombies must cleverly navigate their way around the environment, whatever its arrangement, finding their way toward the player to engage in combat, as though they really had brains! To achieve this, a navigation mesh is required. This is a nonvisible mesh asset, generated by Unity, to approximate the scene floor, for both exterior and interior environments. More accurately, it represents the total walkable floor of the scene-the area over which NPCs may maneuver for travelling from point to point. To access the navigation mesh features, click on Window | Navigation from the application menu. This opens the Navigation mesh window, which can be docked into the object Inspector.

Accessing...

Occlusion Culling


Unity imposes no official limits on the size of your scene, and there's no established convention or industry-standard making recommendations about scene size. This is a decision largely in your hands. But there will certainly be a limit in a practical sense. The complexity of meshes, materials, and special effects combine together with the number of meshes and their spread to determine just how computationally expensive a scene is when presented to a camera with a specific frustum and field of view. Unity tries to make scene rendering easier on the computer by applying Frustum Culling automatically. That is, it silently deactivates (culls) objects outside the viewing volume (frustum) of the camera. As objects leave the frustum, Unity ceases to render them, and as they enter the volume Unity starts rendering them. This optimization works well in many cases, for objects that clearly enter and leave the Frustum.

Camera frustum defines the limits of what can be seen

Using...

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Become a Unity master by creating a practical, in-depth game-development project with Unity
  • Use advanced C# scripting to unlock the complete potential of Unity 5
  • Use Version Control to Effectively Manage and Scale your workflow

Description

Mastering Unity 5.x is for developers wishing to optimize the features of Unity 5.x. With an in-depth focus on a practical project, learn all about Unity architecture and impressive animation techniques. With this book, produce fun games with confidence.

Who is this book for?

If you are a Unity developer who now wants to develop and deploy interesting games by leveraging the new features of Unity 5.x, then this is the book for you. Basic knowledge of C# programming is assumed.

What you will learn

  • Preparation and Asset-Configuring
  • Level Design and Structure
  • Player Controls - Movement
  • Player Controls – Typing & Health
  • Enemies and Artificial Intelligence
  • Project Management & Version Control
  • Persistent Data – Load and Save Game States
  • Performance, Optimization, Mobiles, and More

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jan 27, 2017
Length: 592 pages
Edition : 1st
Language : English
ISBN-13 : 9781785884849
Vendor :
Unity Technologies
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Jan 27, 2017
Length: 592 pages
Edition : 1st
Language : English
ISBN-13 : 9781785884849
Vendor :
Unity Technologies
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 115.97
Mastering Unity 5.x
€41.99
Getting Started with Unity 5.x 2D Game Development
€36.99
Mastering Unity 2D Game  Development
€36.99
Total 115.97 Stars icon

Table of Contents

8 Chapters
1. Preparation and Asset-Configuring Chevron down icon Chevron up icon
2. Level Design and Structure Chevron down icon Chevron up icon
3. Player Controls - Movement Chevron down icon Chevron up icon
4. Player Controls - Typing and Health Chevron down icon Chevron up icon
5. Enemies and Artificial Intelligence Chevron down icon Chevron up icon
6. Project Management and Version Control Chevron down icon Chevron up icon
7. Persistent Data - Load and Save Game States Chevron down icon Chevron up icon
8. Performance, Optimization, Mobiles, and More Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
(1 Ratings)
5 star 0%
4 star 0%
3 star 100%
2 star 0%
1 star 0%
MR B BYFORD May 19, 2017
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
Not bad book if you want to make a very specific type of 3D game
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.