[Unity Basics] 5. Animation Curve

  [Unity Basics] 5. Animation Curve

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

 (1) Curve editing

(1) Animation curve

    Last week we created a simple animation that moves our rectangle from the Y-axis position of 0 at frame 0 to the Y-axis position of 3 at frame 30.

    If the object is moving in a straight line at a uniform speed , we can know that at the 15th frame, the Y-axis position is 1.5, and at the 20th frame the Y-axis position is 2. Is this actually true? 

    Unfortunately, although the position of the object in frame 15 is indeed at 1.5, the position of the Y-axis in frame 20 is indeed at 2.22, which is inconsistent with our preset uniform motion. Then we need to figure out what movement the object is doing at this time . , we can derive today’s protagonist animation curve

    In the lower left of our animation editor, there is a dopesheet default button and curves mode. By clicking curves, we can observe what kind of movement the object is doing over time.

    From the picture above, we can observe that the Y-axis (green) of the object performs a curved speed-changing movement, which is consistent with the results of our previous data verification.

(2) Curve editing

    So what should we do if we want the object to move at a constant speed?

    It's very simple. We observe that there are two points on the motion curve, which are our key frames from 0 to 30. We only need to select it -> select both tangents (tangents on both sides) -> linear (linear) , and then we can If this motion curve is set to a straight line, the object will move in a straight line at a uniform speed. 

    At this time, if we look at the Y-axis position of the object in frame 20, we can get a result equal to 2.

(3) More curve editing options

    In addition to Both tangents, we can also set left tangents and right tangents , that is, set different values ​​​​for the left and right motion curves of the keyframe.

    In addition to linear (straight line), there are also Free (free curve), constant (constant), and weighted (gravity), etc.

    For example, by doing this, we can make the object move in a curve again.

    Selecting constant allows the object to change position only in a certain frame.

 (2) Animation events

(1) Child node animation

    Now we are going to design a helicopter model to summarize what we have just learned by controlling the rotation of its wings. First import a helicopter model. You can see that it contains a front rotor and a tail rotor.

    We follow what we learned in the last lesson and create two new animations Top and Back in the Animation folder for use by the two wings of the aircraft.

    Put them on their respective components, then open the animation editor and adjust the rotation property of their transform component.

    We set the x-axis rotation angle of the tail animation at frame 0 to 0, and at frame 30 to 360, so that the aircraft tail propeller can rotate once within 30 frames.

    But we see that it is stuck one after another, which is obviously not the propeller rotation effect we want. We should open the animation curve editor to make it move at a uniform speed.

    The rotation animation at the top can also be set according to the gourd painting method. Finally, take a look at the final effect:

(2) Animation callback event

   The animation callback event of u3d can be set to execute the corresponding callback function when running to a certain frame . The specific operation method is:

    Create a C# script to hang on the animated mounted object

    Edit the callback function. For example, I want the aircraft's tail to stop rotating when it reaches the 20th frame.

    void StopRotation()
    {
        Animation ani = GetComponent<Animation>();
        ani.Stop("Back");
    }

    Then in the animation editor, select the frame where you want to execute the callback, right-click Add Animation Event, and select our callback method (if not found, you need to verify whether the c# script has forgotten to be attached to the object)    

Okay, that’s it for today, thanks for reading! ! !
Like and follow! ! !

  

Guess you like

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