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  Game Development - Fourth Edition

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

Product type Book
Published in Jan 2024
Publisher Packt
ISBN-13 9781835085714
Pages 742 pages
Edition 4th Edition
Languages
Authors (2):
Nicolas Alejandro Borromeo Nicolas Alejandro Borromeo
Profile icon Nicolas Alejandro Borromeo
Juan Gabriel Gomila Salas Juan Gabriel Gomila Salas
Profile icon Juan Gabriel Gomila Salas
View More author details

Table of Contents (28) Chapters

Preface 1. Section 1: Getting Started with Unity
2. Embark on Your Unity Journey 3. Crafting Scenes and Game Elements 4. From Blueprint to Reality: Building with Terrain and ProBuilder 5. Seamless Integration: Importing and Integrating Assets 6. Section 2: Mastering Programming and Gameplay Mechanics
7. Unleashing the Power of C# and Visual Scripting 8. Dynamic Motion: Implementing Movement and Spawning 9. Collisions and Health: Detecting Collisions Accurately 10. Victory or Defeat: Win and Lose Conditions 11. Starting Your AI Journey: Building Intelligent Enemies for Your Game 12. Section 3: Elevating Visuals, Effects, and Audio
13. Material Alchemy: Using URP and Shader Graph for Stunning Visuals 14. Captivating Visual Effects: Harnessing Particle Systems and Visual Effect Graph 15. Enlightening Worlds: Illuminating Scenes with the Universal Render Pipeline 16. Immersive Realism: Achieving Fullscreen Effects with Post-Processing 17. Harmonious Soundscapes: Integrating Audio and Music 18. Section 4: Designing User Interfaces, Animations and Advanced Concepts
19. Interface Brilliance: Designing User-Friendly UI 20. Next-Gen UI: Creating Dynamic Interfaces with UI Toolkit 21. Animated Realities: Creating Animations with Animator, Cinemachine, and Timeline 22. Performance Wizardry: Optimizing Your Game with Profiler Tools 23. From Prototype to Executable: Generating and Debugging Your Game 24. AR/VR 25. Massive Worlds: Introduction to DOTS 26. Other Books You May Enjoy
27. Index

Animated Realities: 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 deform 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

Now that we’ve introduced skinned meshes, let’s delve deeper into how skinning functions and its pivotal role in character animation. Then, we are going to bring animated meshes into our project to finally...

Scripting animations

Scripting is crucial in bringing our animations in sync with gameplay. Here, we’ll script our animations to respond dynamically to player actions, making our game more immersive and responsive.

With our player’s Animator Controller 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.

By...

Creating dynamic cameras with Cinemachine

Cameras are a very important subject in video games. They allow the player to see their surroundings and make decisions based on what they see. The game designer usually defines how they behave 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 and where the camera is looking to focus the action during those constantly moving scenes.

Cinemachine is Unity’s advanced suite for camera control, enabling developers to craft dynamic and responsive camera behaviors that enhance the gaming experience. 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 Section 3, Elevating Visuals, Effects, and Audio and also the cameras to be used during cutscenes.

...

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 Game Development - Fourth Edition
Published in: Jan 2024 Publisher: Packt ISBN-13: 9781835085714
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 €14.99/month. Cancel anytime}