Reader small image

You're reading from  Unity 5.x Animation Cookbook

Product typeBook
Published inMay 2016
Reading LevelExpert
PublisherPackt
ISBN-139781785883910
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Maciej Szczesnik
Maciej Szczesnik
author image
Maciej Szczesnik

Not interested. Too busy with current game project. Source: Linkedin.
Read more about Maciej Szczesnik

Right arrow

Chapter 2. Working with the Animation View

This chapter explains the Animation View, which is an essential tool in Unity's animation workflow, and the following topics are covered in this chapter:

  • Using the Animation View to create a flickering light
  • Blending light colors with the Animation View and the Animator Controller
  • Animating object's world position - creating a moving platform
  • Animating object's local position - creating automatic doors
  • Using the Hierarchy to animate local rotation - creating an orbiting planet
  • Animating triggers - creating a death trap
  • Creating an elevator triggered by player input

Introduction


In the first chapter, we imported animations from external 3D packages to Unity. Now we will learn how to use Unity's powerful built-in tool called the Animation View. It allows us to animate almost everything within the editor and can be used to create interesting gameplay mechanisms. Knowledge of this tool is essential to learn future recipes as we will use Animation View a lot.

Using the Animation View to create a flickering light


This first recipe shows how to make a basic animation inside Unity. We will animate a light-intensity value to create an interesting flickering light effect, which is often found in horror or sci-fi games.

Getting ready

Before we start, you need to have a scene with geometry and at least one light. You can also download the example provided; open the project in Unity and go to the folder Chapter 02 Working with the animation view\Recipe 01 Using the animation view to create a flickering light. You will find a scene called Example.unity there, with a point light that has already been animated.

How to do it...

To use the Animation View and create a flickering light, follow these steps:

  1. Open the scene and select a light you want to animate.
  2. With the light selected, go to Window | Animation. The Animation View will open.
  3. To create a new animation, click on the Create button, as shown in the following screenshot:

  1. Create New Animation Clip will appear...

Blending light colors with the Animation View and the Animator Controller


This recipe shows how to use Animation Controllers with the clips created in Animation View.

Getting ready

We will animate the light color in this example. You need to have a scene with at least one light and a mesh to see the effect. You can also download the provided example Unity project and go to the Chapter 02 Working with the animation view\Recipe 02 Using the animation view and the animator controller to blend light colors directory. You will find a scene called Example.unity there, with a direction light that has already been animated. In this example, we also animate the background color of the camera (the camera is a child object of the directional light).

How to do it...

To blend animations (colors in this example) of a game object, you need to follow these steps:

  1. Open the scene and select the light game object in the Hierarchy.
  2. With the light selected, go to Window | Animation to open the Animation View and create...

Animating an object's world position - creating a moving platform


In this recipe, we will create a very common gameplay mechanism: a moving platform. We will use a Rigid body for our character and an animated, kinematic Rigid body for the platform.

Getting ready

Before we start, you should have a scene with your character and a platform you want to animate. You can use the example project; go to the Chapter 02 Working with the animation view\Recipe 03 Animating objects world position - creating a moving platform directory. There is a scene called Example.unity there. If you open it, you will find a Sheep character in the Hierarchy. This is our character, using the Rigidbody component and a Simple Move script to move. There is also a Moving Platform game object in the Hierarchy. This is the kinematic rigid body with a Platform script attached to it. It also has an Animator component and an Animator Controller with just one animation in it. This animation makes the platform move.

How to do it...

Animating object's local position - creating automatic doors


In this recipe, we will learn how to animate an object's local position to be able to use the same animated object in multiple locations in the scene. We will create another common gameplay mechanism, automatic door, as an example.

Getting ready

To make an animated door, you should have two objects ready: the Door Frame and the Door. The Door should be a child of the Frame in the Hierarchy. It should be placed in the closed position. We assume that our Door will slide upward when opening. You should also have a player character with the Player tag assigned. The character should use a Rigidbody component to move or have a kinematic Rigidbodycomponent. We will use triggers for our doors, and triggers react to Rigid bodies only. You can also go to the Chapter 02 Working with the animation view\Recipe 04 Animating objects local position - creating automatic doors directory and find the Example.unity scene there. If you open it, you...

Using the Hierarchy to animate local rotation - creating an orbiting planet


In this recipe, we will explore local transform animations further. We will use the Hierarchy and create smart parent-child relationships between our game objects to make an interesting effect of orbiting planets. Learning how to animate an object's local position and rotation and use the Hierarchy to our advantage is key to getting the most of Unity's animation system.

Getting ready

Before we start, you need to prepare at least two objects to animate. We are using planets in this example. You can also use the example Unity project provided and go to the Chapter 02 Working with the animation view\Recipe 05 Using the hierarchy to animate local rotation - creating an orbiting planet directory. You will find an Example.unity scene there. There is a Planets game object with an Animator component and an Animator Controller assigned. If you select the Planets game object and go to Window | Animation, you can edit the animation...

Animating triggers - creating a death trap


In this recipe, we will animate a trigger position and use it to create a death trap. You can use Unity's Animation View to create various game play mechanisms with minimum scripting.

Getting ready

Before we start, you should prepare a death trap model. We are using a "press trap" as an example. It contains two identical moving elements. See the following screenshot:

The model is not skinned and has no rig; instead, the moving elements are separate objects. We will animate them with Unity's Animation View. You can also use the example Unity project provided and go to the Chapter 02 Working with the animation view\Recipe 06 Animating triggers - creating a death trap directory. You will find an Example.unity scene there. If you play the game, you can see the trap working. If you open the scene, you will find the Trap game object with the LeftTrap and RightTrap game objects as its children. Those child objects are the only ones animated in this example...

Creating an elevator triggered by player input


In this last recipe, we will use player input to create a simple elevator.

Getting ready

Before we start, you should prepare an elevator model to contain the objects: the root object called Elevator, the Lift object (this one will be animated), and the ElevatorFrame object, which will work as decoration. The Lift and ElevatorFrame objects should be children of the empty Elevator object. You can also use the example Unity project provided and go to the Chapter 02 Working with the animation view\Recipe 07 Creating an elevator triggered by player input directory. You will find an Example.unity scene there with the Elevator game object and its children Lift and ElevatorFrame objects. The Elevator is already animated in the example assets.

How to do it...

To create an elevator triggered by player input, follow these steps:

  1. Select the root Elevator object and assign an Animator component to it. Set the Update Mode to Animate Physics.
  2. Open Window | Animation...
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Unity 5.x Animation Cookbook
Published in: May 2016Publisher: PacktISBN-13: 9781785883910
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.
undefined
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

Author (1)

author image
Maciej Szczesnik

Not interested. Too busy with current game project. Source: Linkedin.
Read more about Maciej Szczesnik