Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Hands-On Unity 2022 Game Development - Third Edition

You're reading from  Hands-On Unity 2022 Game Development - Third Edition

Product type Book
Published in Oct 2022
Publisher Packt
ISBN-13 9781803236919
Pages 712 pages
Edition 3rd Edition
Languages
Author (1):
Nicolas Alejandro Borromeo Nicolas Alejandro Borromeo
Profile icon Nicolas Alejandro Borromeo

Table of Contents (23) Chapters

Preface 1. Creating a Unity Project 2. Editing Scenes and Game Objects 3. Grayboxing with Terrain and ProBuilder 4. Importing and Integrating Assets 5. Introduction to C# and Visual Scripting 6. Implementing Movement and Spawning 7. Physics Collisions and Health System 8. Win and Lose Conditions 9. Implementing Game AI for Building Enemies 10. Materials and Effects with URP and Shader Graph 11. Visual Effects with Particle Systems and Visual Effect Graph 12. Lighting Using the Universal Render Pipeline 13. Full-Screen Effects with Post-Processing 14. Sound and Music Integration 15. User Interface Design 16. Creating a UI with the UI Toolkit 17. Creating Animations with Animator, Cinemachine, and Timeline 18. Optimization with Profiler, Frame Debugger, and Memory Profiler 19. Generating and Debugging an Executable 20. Augmented Reality in Unity 21. Other Books You May Enjoy
22. Index

Creating Animations with Animator, Cinemachine, and Timeline

Sometimes, we need to move objects in a predetermined way, such as with cutscenes, or specific character animations, such as jumping, running, and so on. In this chapter, we will go over several Unity animation systems to create all the possible movements of objects we can get without scripting.

In this chapter, we will examine the following animation concepts:

  • Using Skinning Animation with Animator
  • Scripting animations
  • Creating dynamic cameras with Cinemachine
  • Creating cutscenes with Timeline

By the end of this chapter, you will be able to create cutscenes to tell the history of your game or highlight specific areas of your level, as well as create dynamic cameras that are capable of giving an accurate look to your game, regardless of the situation.

Using Skinning Animation with Animator

So far, we have used what are called static meshes, which are solid three-dimensional models that are not supposed to bend or animate in any way (aside from moving separately, like the doors of a car).

We also have another kind of mesh, called skinned meshes, which are meshes that have the ability to bend based on a skeleton, so they can emulate the muscle movements of the human body. We are going to explore how to integrate animated humanoid characters into our project to create enemy and player movements.

In this section, we will examine the following skeletal mesh concepts:

  • Understanding skinning
  • Importing skinned meshes
  • Integration using Animator Controllers
  • Using Avatar Masks

We are going to explore the concept of skinning and how it allows you to animate characters. Then, we are going to bring animated meshes into our project to finally apply animations to them. Let’s start by discussing...

Scripting animations

With our player’s Animator ready, it is time to do some scripting to make these parameters be affected by the actual behavior of the player and match the player’s. In this section we will do the following to achieve this:

  • Script shooting animations
  • Script movement animations

Let’s start making our characters execute the Shoot animation when necessary.

Scripting player shooting animations

So far, we have created a behavior to shoot each time we press a key, but the animation is prepared for sustained fire. We can make our PlayerShooting script shoot a bullet every X number of seconds while we keep the Fire key pressed to match the animation, instead of having to press the key repeatedly.

Let’s see how to do this:

  1. In the PlayerShooting script, add a public float field called fireRate, which will measure the seconds between bullet spawns. Remember to set this value in the Inspector of the...

Creating dynamic cameras with Cinemachine

Cameras are a very important subject in video games. They allow the player to see their surroundings to make decisions based on what they see. The game designer usually defines how it behaves to get the exact gameplay experience they want, and that’s no easy task. A lot of behaviors must be layered to get the exact feeling. Also, for cutscenes, it is important to control the path that the camera will be traversing during it and where the camera is looking to focus the action during those constantly moving scenes.

In this chapter, we will use the Cinemachine package to create both the dynamic cameras that will follow the player’s movements, which we will code in Part 3, and also, the cameras to be used during cutscenes.

In this section, we will examine the following Cinemachine concepts:

  • Creating camera behaviors
  • Creating dolly tracks

Let’s start by discussing how to create a Cinemachine...

Creating cutscenes with Timeline

We have our intro camera, but that’s not enough to create a cutscene. A proper cutscene is a sequence of actions happening at the exact moment that they should happen, coordinating several objects to act as intended. We can have actions such as enabling and disabling objects, switching cameras, playing sounds, moving objects, and so on. To do this, Unity offers Timeline, which is a sequencer of actions to coordinate those kinds of cutscenes. We will use Timeline to create an intro cutscene for our scene, showing the level before starting the game.

In this section, we will examine the following Timeline concepts:

  • Creating animation clips
  • Sequencing our intro cutscene

We are going to see how to create our own animation clips in Unity to animate our GameObjects and then place them inside a cutscene to coordinate their activation, using the Timeline sequencer tool. Let’s start by creating a camera animation to...

Summary

In this chapter, we introduced the different animation systems that Unity provides for different requirements. We discussed importing character animations and controlling them with Animation Controllers. We also saw how to make cameras that can react to the game’s current situation, such as the player’s position, or that can be used during cutscenes. Finally, we looked at Timeline and the animation system to create an intro cutscene for our game. These tools are useful for making the animators in our team work directly in Unity without the hassle of integrating external assets (except for character animations) and also preventing the programmer from creating repetitive scripts to create animations, wasting time in the process.

Now, you are able to import and create animation clips in Unity, as well as apply them to GameObjects to make them move according to the clips. Also, you can place them in the Timeline sequencer to coordinate them and create cutscenes...

lock icon The rest of the chapter is locked
You have been reading a chapter from
Hands-On Unity 2022 Game Development - Third Edition
Published in: Oct 2022 Publisher: Packt ISBN-13: 9781803236919
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}