Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Animator and Animation | Unity Animation System
Fighting Game in Unity
course content

Conteúdo do Curso

Fighting Game in Unity

Fighting Game in Unity

1. Unity Animation System
2. Player Behavior
3. Enemy Behavior
4. Improve the Game
5. Improve the Flappy Bird Game

Animator and Animation

In Unity, the animator plays a pivotal role in bringing game objects to life through animations. By linking animation clips with transitions and parameters, animators craft dynamic movements and behaviors for characters and objects within the game world. These animations contain keyframe data and settings that define how objects move and interact, crucial for creating immersive and engaging gameplay experiences.

Animator

To let Unity know that this object may have animations, we need to add the animator component.

And we also need to create a controller to add it to the animator.

Next, if we click on the object from the hierarchy and open the animator panel, it will be something similar to this.

In Unity's Animator panel, animators control the flow of animations within a game.

Parameters serve as variables that influence transitions between animation states. The Entry State defines the initial animation when a game starts, while Any State allows for transitions from any state. Parameters, including booleans, floats, and integers, enable dynamic animation changes based on game conditions.

Animations

First, when you click on your object and open the animations panel, it will look like this.

Since there are no animations, it will ask you to create an animation clip for the object. When you click create, it will ask you to select a name and location for the animation. After creating an animation, the animator and the animations panel will change.

In Unity's Animation panel, developers can create, edit, and manage animations for game objects. Key components include the Animation Timeline, which displays keyframes and animation tracks, facilitating precise editing of animations over time. If we want to change parameters of the animation, we can select it in the assets folder and change it.

  • Loop Time: Animation restarts seamlessly from end to beginning;
  • Loop Pose: Smoothly transitions final frame to initial frame for seamless looping;
  • Offset: Specifies time delay for animation playback, useful for synchronization and variation.

Recording in Animation Panel

In Unity's Animation panel, the Record button is a crucial tool for animators. When activated, it enables the recording of keyframe animation directly within the Unity Editor. By manipulating an object's properties (such as position, rotation, or scale) in the Scene view or Inspector window while recording, users can create keyframes automatically.

Adding Another Clip

We can add another clip to our object by clicking Create New Clip:

Transitions Between Animations

After having different clips, we can set up the transitions between them in the animator. For creating the transition, first, we select the target and click Make Transition, then select the destination.

Like this, we have a transition between those two animations.

If we click on the transition, we will have this view in the inspector:

Has Exit Time

When enabled, it ensures that the current animation completes before transitioning to the next state, based on the exit time specified in the transition. Disabling Has Exit Time allows for more dynamic and immediate transitions between states, often based on conditions or triggers. We will see more about the Has Exit Time uses in action.

Create Parameters for Transition Condition

For setting up a condition in the transition, we need to create parameters.

Now, create a condition by pressing the + button.

For transitioning from state A to state B, we need to ensure that can_Translate = true.

Example: Human Actions

Imagine we're controlling a character in a game. We have animations for playing with a computer, sleeping, and eating.

Conditions for Transitions

To control when our character transitions between animations, we'll use conditions. For instance, let's say we have a "hungry" condition. When this condition is true, we want our character to transition from playing with the computer to eating.

Implementing the Transition

In Unity's Animator, we'll create a transition from the "playing with computer" animation state to the "eating" animation state. We'll set the condition for this transition to be the "hungry" boolean. So, when "hungry" becomes true, Unity will automatically transition our character from playing to eating.

We could add more conditions and transitions. For example, we could have a "tired" condition that triggers a transition from playing to sleeping. We can also blend animations for smoother transitions.

So, the animator in Unity works exactly like us: every block is an action that we can do in our daily life, and the arrows hold the condition for changing to that animation.

What is the purpose of an Animator component in Unity?

Selecione a resposta correta

Tudo estava claro?

Seção 1. Capítulo 2
We're sorry to hear that something went wrong. What happened?
some-alt