[Basics of Unity] 6. Animation state machine

  [Basics of Unity] 6. Animation state machine

        Hello everyone, I am Lampard~~
        Welcome to the Unity basic series blog. The knowledge I learned comes from Teacher Afa from Station B~Thank you 

(1) Animator Controller component

(1) Create components

    The Animator Controller component is a component used by Unity to control and manage animation status. What is a state machine and why was this concept introduced? 

    A character may have multiple animation states such as running, jumping, standing, attacking, etc. In the past, we could create and switch different actions of the character through code. But this firstly increases the workload of the program, and secondly it is not intuitive. To see the actual effects of the art (such as running animation and attack animation), the program needs to enter the resources into the package body. , write the code well before you can test it.

    Therefore, Unity provides this component so that art students can manage the animation display in different states in the editor and see the actual effects; so that program students only need to pay attention to the variable changes in different states and do not need to manage the addition and deletion of animations.

    Just right-click create and select Animator Controller to create an animation manager component

(2) Animation status editing interface

    Double-click the Animator Controller we created to open the animation editing interface. We can see the initial Animator Controller comes with three states, namely Any State, Entry and Exit

Any State

    represents a special state of any state. For example, if we hope thatthe character may switch to the death state in any state, then Any State can help us do it. When you find that a certain state can jump to from any state under the same conditions, then you can use Any State to simplify the transition relationship

Entry status 

represents the entry state of the state machine. When we add an Animator component to a GameObject, this component will start to play its role.
If the Animator Controller controls the playback of multiple Animations, which animation will the Animator component play by default? Determined by Entry.
But Entry itself does not contain animation, but points to a state with animation and sets it as the default state . Statuses that are set as default will appear in orange

Exit status

Indicates the exit status of the state machine, marked in red. If your animation controller only has one layer, this state may not be useful. But when you need to return to the previous layer (Layer) from the sub-state machine, just point the state to Exit.

(2) Animation status

(1) Add & delete & rename animation status

    If you don’t understand the introduction to the three initial states above, it doesn’t matter, because we will learn from the beginning

    The first step is to create and delete. In the animation state editor, right-click create state to create an animation state. Select the animation state and right-click delete to delete it (the initial three states cannot be deleted)

    Secondly, if you want to rename a state, you only need to select the state and find the name attribute modification in the Inspector property panel on the right.

(2) Properties of animation state

    In the animation panel, we can see that the status also has the following attributes. Don’t worry too much. You will definitely use them in the future. Now we can briefly take a look at the introduction:

(3) Contact of animation status

    There will be a connection between animation states, such as being hit followed by death, such as forward shaking state followed by attack. The relationship between these states,unity will use transition to define this set of relationships, and in the state editor, it will be presented with a line segment pointing 

     As shown in the picture above, we have made a two-way connection between state1 and state2, which means that S1 can be converted into S2, and S2 can also be converted into S1.Their connection is on the right The transitions in the side attribute panel are recorded. If you want to delete their relationship, just delete them in transitions

    We know that entry will point to the initial animation state. For example, the default is to point to the S1 state. Then if I want S2 to be the initial state, I only need to select the S2 state and right-click Set as default state

(3) Hang up status animation

(1) Create animation animation

    There are a lot of them above, and some readers may start to complain: Does this have anything to do with animation? ? ?

    No need to rush! ! It’s finally time to get to the critical step of attaching animation to the status. The first is to create a simple animation. For example, we add a rising animation to the previous helicopter, and simply edit its Y-axis to increase over time;

(2) Add animation to state motion

    Select the animation state we want to hang in, and then drag the created animation to the motion attribute bar to hang it up.

    Click to run and see. The animation state enters from entry to State1, and then the fly animation is played. And our helicopter took off~

     What will happen if we add an animation state State2 at this time and let State1 enter State2 after playing?

    As we thought, after the fly action is played once, it enters state2. Because state2 does not define other motion animations, the helicopter remains motionless. 

    Okay, let’s stop here today and do more complex animation editing operations next week~

    Like and follow! ! !

Guess you like

Origin blog.csdn.net/cooclc/article/details/133842712