2023-01-12 20:49:14 +01:00
|
|
|
|
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
|
|
Introduction to the animation features
|
|
|
|
|
======================================
|
|
|
|
|
|
2023-01-12 19:32:38 +01:00
|
|
|
|
The `AnimationPlayer` node allows you to create anything
|
2022-03-18 17:46:08 +01:00
|
|
|
|
from simple to complex animations.
|
|
|
|
|
|
|
|
|
|
In this guide you learn to:
|
|
|
|
|
|
|
|
|
|
- Work with the Animation Panel
|
|
|
|
|
- Animate any property of any node
|
|
|
|
|
- Create a simple animation
|
|
|
|
|
- Call functions with the powerful Call Function Tracks
|
|
|
|
|
|
|
|
|
|
In Godot, you can animate anything available in the Inspector, such as
|
|
|
|
|
Node transforms, sprites, UI elements, particles, visibility and color
|
|
|
|
|
of materials, and so on. You can also modify values of script variables
|
|
|
|
|
and call any function.
|
|
|
|
|
|
|
|
|
|
Create an AnimationPlayer node
|
|
|
|
|
------------------------------
|
|
|
|
|
|
|
|
|
|
To use the animation tools we first have to create an
|
2023-01-12 19:32:38 +01:00
|
|
|
|
`AnimationPlayer` node.
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
|
|
The AnimationPlayer node type is the data container for your animations.
|
|
|
|
|
One AnimationPlayer node can hold multiple animations, that can
|
|
|
|
|
automatically transition to one another.
|
|
|
|
|
|
2023-01-12 20:16:00 +01:00
|
|
|
|
.. figure:: img/animation_create_animationplayer.png)
|
2022-03-18 17:46:08 +01:00
|
|
|
|
:alt: The AnimationPlayer node
|
|
|
|
|
|
|
|
|
|
The AnimationPlayer node
|
|
|
|
|
|
|
|
|
|
After creating one click on the AnimationPlayer node in the Node tab to
|
|
|
|
|
open the Animation Panel at the bottom of the viewport.
|
|
|
|
|
|
2023-01-12 20:16:00 +01:00
|
|
|
|
.. figure:: img/animation_animation_panel.png)
|
2022-03-18 17:46:08 +01:00
|
|
|
|
:alt: The animation panel position
|
|
|
|
|
|
|
|
|
|
The animation panel position
|
|
|
|
|
|
|
|
|
|
It consists of four parts:
|
|
|
|
|
|
2023-01-12 20:16:00 +01:00
|
|
|
|
.. figure:: img/animation_animation_panel_overview.png)
|
2022-03-18 17:46:08 +01:00
|
|
|
|
:alt: The animation panel
|
|
|
|
|
|
|
|
|
|
The animation panel
|
|
|
|
|
|
|
|
|
|
- Animation controls (i.e. add, load, save, and delete animations)
|
|
|
|
|
- The tracks listing
|
|
|
|
|
- The timeline with keyframes
|
|
|
|
|
- The timeline and track controls, where you can zoom the timeline and
|
|
|
|
|
edit tracks for example.
|
|
|
|
|
|
|
|
|
|
Computer animation relies on keyframes
|
|
|
|
|
--------------------------------------
|
|
|
|
|
|
|
|
|
|
A keyframe defines the value of a property at a certain point in time.
|
|
|
|
|
|
|
|
|
|
Diamond shapes represent keyframes in the timeline. A line between two
|
|
|
|
|
keyframes indicates that the value hasn't changed.
|
|
|
|
|
|
2023-01-12 20:16:00 +01:00
|
|
|
|
.. figure:: img/animation_keyframes.png)
|
2022-03-18 17:46:08 +01:00
|
|
|
|
:alt: Keyframes in Godot
|
|
|
|
|
|
|
|
|
|
Keyframes in Godot
|
|
|
|
|
|
|
|
|
|
The engine interpolates values between keyframes, resulting in a gradual
|
|
|
|
|
change in values over time.
|
|
|
|
|
|
2023-01-12 20:16:00 +01:00
|
|
|
|
.. figure:: img/animation_illustration.png)
|
2022-03-18 17:46:08 +01:00
|
|
|
|
:alt: Two keyframes are all it takes to obtain a smooth motion
|
|
|
|
|
|
|
|
|
|
Two keyframes are all it takes to obtain a smooth motion
|
|
|
|
|
|
|
|
|
|
The timeline lets you insert keyframes and change their timing. It also
|
|
|
|
|
defines how long the animation is.
|
|
|
|
|
|
2023-01-12 20:16:00 +01:00
|
|
|
|
.. figure:: img/animation_timeline.png)
|
2022-03-18 17:46:08 +01:00
|
|
|
|
:alt: The timeline in the animation panel
|
|
|
|
|
|
|
|
|
|
The timeline in the animation panel
|
|
|
|
|
|
|
|
|
|
Each line of the Animation Panel is an animation track. Normal and
|
|
|
|
|
Transform tracks reference node properties. Their name or id is a path
|
|
|
|
|
to the node and the affected property.
|
|
|
|
|
|
2023-01-12 20:16:00 +01:00
|
|
|
|
.. figure:: img/animation_normal_track.png)
|
2022-03-18 17:46:08 +01:00
|
|
|
|
:alt: Example of Normal animation tracks
|
|
|
|
|
|
|
|
|
|
Example of Normal animation tracks
|
|
|
|
|
|
|
|
|
|
.. tip::
|
|
|
|
|
|
|
|
|
|
If you animate the wrong property, you can edit a track's path anytime.
|
|
|
|
|
Double click on it and type the new path. Play the animation using the
|
|
|
|
|
"Play from beginning" button |Play from beginning| (or pressing
|
|
|
|
|
:kbd:`Shift + D` on keyboard) to see the changes instantly.
|
|
|
|
|
|
|
|
|
|
Tutorial: Creating a simple animation
|
|
|
|
|
-------------------------------------
|
|
|
|
|
|
|
|
|
|
Scene setup
|
|
|
|
|
~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
For this tutorial, we'll create a Sprite node with an AnimationPlayer as
|
|
|
|
|
its child. We will animate the sprite to move between two points on the screen.
|
|
|
|
|
|
2023-01-12 20:16:00 +01:00
|
|
|
|
.. figure:: img/animation_animation_player_tree.png)
|
2022-03-18 17:46:08 +01:00
|
|
|
|
:alt: Our scene setup
|
|
|
|
|
|
|
|
|
|
Our scene setup
|
|
|
|
|
|
2023-01-12 20:55:57 +01:00
|
|
|
|
Warning:
|
|
|
|
|
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
2022-09-10 12:15:58 +02:00
|
|
|
|
AnimationPlayer inherits from Node instead of Node2D or Spatial, which means
|
2022-03-18 17:46:08 +01:00
|
|
|
|
that the child nodes will not inherit the transform from the parent nodes
|
|
|
|
|
due to a bare Node being present in the hierarchy.
|
|
|
|
|
|
|
|
|
|
Therefore, it is not recommended to add nodes that have a 2D/3D transform
|
|
|
|
|
as a child of an AnimationPlayer node.
|
|
|
|
|
|
|
|
|
|
The sprite holds an image texture. We animate that sprite to move
|
|
|
|
|
between two points on the screen. For this tutorial, use the default Godot
|
|
|
|
|
icon as the sprite's texture. As a starting point, move the sprite
|
|
|
|
|
to a left position on the screen.
|
|
|
|
|
|
|
|
|
|
Select the AnimationPlayer node, then click the "Animation" button in the
|
|
|
|
|
animation editor. From the list select "New" (|Add
|
|
|
|
|
Animation|) to add a new animation. And Enter a name for the animation in the
|
|
|
|
|
dialog box.
|
|
|
|
|
|
2023-01-12 20:16:00 +01:00
|
|
|
|
.. figure:: img/animation_create_new_animation.png)
|
2022-03-18 17:46:08 +01:00
|
|
|
|
:alt: Add a new animation
|
|
|
|
|
|
|
|
|
|
Add a new animation
|
|
|
|
|
|
|
|
|
|
Adding a track
|
|
|
|
|
~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
To add a new track for our sprite, select it and take a look in the
|
|
|
|
|
toolbar:
|
|
|
|
|
|
2023-01-12 20:16:00 +01:00
|
|
|
|
.. figure:: img/animation_convenience_buttons.png)
|
2022-03-18 17:46:08 +01:00
|
|
|
|
:alt: Convenience buttons
|
|
|
|
|
|
|
|
|
|
Convenience buttons
|
|
|
|
|
|
|
|
|
|
These switches and buttons allow you to add keyframes for the selected
|
|
|
|
|
node's location, rotation, and scale respectively.
|
|
|
|
|
|
|
|
|
|
Deselect rotation, because we are only interested in the location of our
|
|
|
|
|
sprite for this tutorial and click on the key button.
|
|
|
|
|
|
|
|
|
|
As we don't have a track already set up for the transform/location
|
|
|
|
|
property, Godot asks whether it should set it up for us. Click **Create**.
|
|
|
|
|
|
|
|
|
|
This creates a new track and our first keyframe at the beginning of
|
|
|
|
|
the timeline:
|
|
|
|
|
|
2023-01-12 20:16:00 +01:00
|
|
|
|
.. figure:: img/animation_track.png)
|
2022-03-18 17:46:08 +01:00
|
|
|
|
:alt: The sprite track
|
|
|
|
|
|
|
|
|
|
The sprite track
|
|
|
|
|
|
|
|
|
|
The second keyframe
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
Now we need to set the destination where our sprite should be headed and
|
|
|
|
|
how much time it takes to get there.
|
|
|
|
|
|
|
|
|
|
Let's say, we want it to take 2 seconds to go to the other point. By
|
|
|
|
|
default the animation is set to last only 1 second, so change this in
|
|
|
|
|
the timeline controls in animation panel's lower panel to 2.
|
|
|
|
|
|
2023-01-12 20:16:00 +01:00
|
|
|
|
.. figure:: img/animation_set_length.png)
|
2022-03-18 17:46:08 +01:00
|
|
|
|
:alt: Animation length
|
|
|
|
|
|
|
|
|
|
Animation length
|
|
|
|
|
|
|
|
|
|
Click on the timeline header near the 2-second mark and move the sprite
|
|
|
|
|
to the target destination on the right side.
|
|
|
|
|
|
|
|
|
|
Again, click the key button in the toolbar. This creates our second
|
|
|
|
|
keyframe.
|
|
|
|
|
|
|
|
|
|
Run the animation
|
|
|
|
|
~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
Click on the "Play from beginning" (|Play from beginning|) button.
|
|
|
|
|
|
|
|
|
|
Yay! Our animation runs:
|
|
|
|
|
|
2023-01-12 20:16:00 +01:00
|
|
|
|
.. figure:: img/animation_simple.gif)
|
2022-03-18 17:46:08 +01:00
|
|
|
|
:alt: The animation
|
|
|
|
|
|
|
|
|
|
The animation
|
|
|
|
|
|
|
|
|
|
Back and forth
|
|
|
|
|
~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
Godot has an additional feature here. Like said before,
|
|
|
|
|
Godot always calculates the frames between two keyframes. In a loop, the
|
|
|
|
|
first keyframe is also the last keyframe, if no keyframe is specified at
|
|
|
|
|
the end.
|
|
|
|
|
|
2023-01-12 20:16:00 +01:00
|
|
|
|
.. figure:: img/animation_loop.png)
|
2022-03-18 17:46:08 +01:00
|
|
|
|
:alt: Animation loop
|
|
|
|
|
|
|
|
|
|
Animation loop
|
|
|
|
|
|
|
|
|
|
If you set the animation length to 4 seconds now, the animation moves
|
|
|
|
|
back and forth. You can change this behavior if you change the track's
|
|
|
|
|
loop mode. This is covered in the next chapter.
|
|
|
|
|
|
|
|
|
|
Track settings
|
|
|
|
|
~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
Each track has a settings panel at the end, where you can set the update
|
|
|
|
|
mode, the track interpolation, and the loop mode.
|
|
|
|
|
|
2023-01-12 20:16:00 +01:00
|
|
|
|
.. figure:: img/animation_track_settings.png)
|
2022-03-18 17:46:08 +01:00
|
|
|
|
:alt: Track settings
|
|
|
|
|
|
|
|
|
|
Track settings
|
|
|
|
|
|
|
|
|
|
The update mode of a track tells Godot when to update the property
|
|
|
|
|
values. This can be:
|
|
|
|
|
|
|
|
|
|
- **Continuous:** Update the property on each frame.
|
|
|
|
|
- **Discrete:** Only update the property on keyframes.
|
|
|
|
|
- **Trigger:** Only update the property on keyframes or triggers.
|
|
|
|
|
Triggers are a type of keyframe used by the
|
2023-01-12 19:43:03 +01:00
|
|
|
|
`current_animation` property of a `AnimationPlayer`,
|
2022-03-18 17:46:08 +01:00
|
|
|
|
and Animation Playback tracks.
|
2023-01-12 19:43:03 +01:00
|
|
|
|
- **Capture:** If the first keyframe's time is greater than `0.0`, the
|
2022-03-18 17:46:08 +01:00
|
|
|
|
current value of the property will be remembered and
|
|
|
|
|
will be blended with the first animation key. For example, you
|
|
|
|
|
could use the Capture mode to move a node that's located anywhere
|
|
|
|
|
to a specific location.
|
|
|
|
|
|
2023-01-12 20:16:00 +01:00
|
|
|
|
.. figure:: img/animation_track_rate.png)
|
2022-03-18 17:46:08 +01:00
|
|
|
|
:alt: Track mode
|
|
|
|
|
|
|
|
|
|
Track mode
|
|
|
|
|
|
|
|
|
|
In normal animations, you usually use "Continuous". The other types are
|
|
|
|
|
used to script complex animations.
|
|
|
|
|
|
|
|
|
|
The interpolation tells Godot how to calculate the frame values between
|
|
|
|
|
the keyframes. These interpolation modes are supported:
|
|
|
|
|
|
|
|
|
|
- Nearest: Set the nearest keyframe value
|
|
|
|
|
- Linear: Set the value based on a linear function calculation between
|
|
|
|
|
the two keyframes
|
|
|
|
|
- Cubic: Set the value based on a cubic function calculation between
|
|
|
|
|
the two keyframes
|
|
|
|
|
|
2023-01-12 20:16:00 +01:00
|
|
|
|
.. figure:: img/animation_track_interpolation.png)
|
2022-03-18 17:46:08 +01:00
|
|
|
|
:alt: Track interpolation
|
|
|
|
|
|
|
|
|
|
Track interpolation
|
|
|
|
|
|
|
|
|
|
Cubic interpolation leads to a more natural movement, where the
|
|
|
|
|
animation is slower at a keyframe and faster between keyframes. This is
|
|
|
|
|
usually used for character animation. Linear interpolation creates more
|
|
|
|
|
of a robotic movement.
|
|
|
|
|
|
|
|
|
|
Godot supports two loop modes, which affect the animation if it's set to
|
|
|
|
|
loop:
|
|
|
|
|
|
2023-01-12 20:16:00 +01:00
|
|
|
|
.. figure:: img/animation_track_loop_modes.png)
|
2022-03-18 17:46:08 +01:00
|
|
|
|
:alt: Loop modes
|
|
|
|
|
|
|
|
|
|
Loop modes
|
|
|
|
|
|
|
|
|
|
- Clamp loop interpolation: When this is selected, the animation stops
|
|
|
|
|
after the last keyframe for this track. When the first keyframe is
|
|
|
|
|
reached again, the animation will reset to its values.
|
|
|
|
|
- Wrap loop interpolation: When this is selected, Godot calculates the
|
|
|
|
|
animation after the last keyframe to reach the values of the first
|
|
|
|
|
keyframe again.
|
|
|
|
|
|
|
|
|
|
Keyframes for other properties
|
|
|
|
|
------------------------------
|
|
|
|
|
|
|
|
|
|
Godot doesn't restrict you to only edit transform properties. Every
|
|
|
|
|
property can be used as a track where you can set keyframes.
|
|
|
|
|
|
|
|
|
|
If you select your sprite while the animation panel is visible, you get
|
|
|
|
|
a small keyframe button for all the sprite's properties. Click on
|
|
|
|
|
this button and Godot automatically adds a track and keyframe to the
|
|
|
|
|
current animation.
|
|
|
|
|
|
2023-01-12 20:16:00 +01:00
|
|
|
|
.. figure:: img/animation_properties_keyframe.png)
|
2022-03-18 17:46:08 +01:00
|
|
|
|
:alt: Keyframes for other properties
|
|
|
|
|
|
|
|
|
|
Keyframes for other properties
|
|
|
|
|
|
|
|
|
|
Edit keyframes
|
|
|
|
|
--------------
|
|
|
|
|
|
|
|
|
|
For advanced use and to edit keyframes in detail, You can click on them
|
|
|
|
|
to bring up the keyframe editor in the inspector. You can use this to
|
|
|
|
|
directly edit its values.
|
|
|
|
|
|
2023-01-12 20:16:00 +01:00
|
|
|
|
.. figure:: img/animation_keyframe_editor_key.png)
|
2022-03-18 17:46:08 +01:00
|
|
|
|
:alt: Keyframe editor editing a key
|
|
|
|
|
|
|
|
|
|
Keyframe editor editing a key
|
|
|
|
|
|
|
|
|
|
Additionally, you can also edit the easing value for this keyframe by
|
|
|
|
|
clicking and dragging the easing setting. This tells Godot, how to change
|
|
|
|
|
the property values when it reaches this keyframe.
|
|
|
|
|
|
|
|
|
|
You usually tweak your animations this way, when the movement doesn't
|
|
|
|
|
"look right".
|
|
|
|
|
|
|
|
|
|
Advanced: Call Method tracks
|
|
|
|
|
----------------------------
|
|
|
|
|
|
|
|
|
|
Godot's animation engine doesn't stop here. If you're already
|
|
|
|
|
comfortable with Godot's scripting language
|
2023-01-12 19:29:11 +01:00
|
|
|
|
`doc_gdscript` and :doc:`/classes/index` you
|
2022-03-18 17:46:08 +01:00
|
|
|
|
know that each node type is a class and has a bunch of callable
|
|
|
|
|
methods.
|
|
|
|
|
|
2023-01-12 19:32:38 +01:00
|
|
|
|
For example, the `AudioStreamPlayer` node type has a
|
2022-03-18 17:46:08 +01:00
|
|
|
|
method to play an audio stream.
|
|
|
|
|
|
|
|
|
|
Wouldn't it be great to use a method at a specific keyframe in an
|
|
|
|
|
animation? This is where "Call Method Tracks" come in handy. These tracks
|
|
|
|
|
reference a node again, this time without a reference to a property.
|
|
|
|
|
Instead, a keyframe holds the name and arguments of a method, that
|
|
|
|
|
Godot should call when it reaches this keyframe.
|
|
|
|
|
|
|
|
|
|
To demonstrate, we're going to use a call method track to play audio at a
|
|
|
|
|
specific keyframe. Normally to play audio you should use an audio track,
|
|
|
|
|
but for the sake of demonstrating methods we're going to do it this way.
|
|
|
|
|
|
2023-01-12 19:32:38 +01:00
|
|
|
|
Add a `AudioStreamPlayer` to the Scene Tree and setup a
|
2022-03-18 17:46:08 +01:00
|
|
|
|
stream using an audio file you put in your project.
|
|
|
|
|
|
|
|
|
|
Click on "Add track" (|Add track|) on the animation panel's track
|
|
|
|
|
controls.
|
|
|
|
|
|
|
|
|
|
Select "Add Call Method Track" from the list of possible track types.
|
|
|
|
|
|
2023-01-12 20:16:00 +01:00
|
|
|
|
.. figure:: img/animation_add_call_method_track.png)
|
2022-03-18 17:46:08 +01:00
|
|
|
|
:alt: Add Call Method Track
|
|
|
|
|
|
|
|
|
|
Add Call Method Track
|
|
|
|
|
|
2023-01-12 19:32:38 +01:00
|
|
|
|
Select the `AudioStreamPlayer` node in the selection
|
2022-03-18 17:46:08 +01:00
|
|
|
|
window. Godot adds the track with the reference to the node.
|
|
|
|
|
|
2023-01-12 20:16:00 +01:00
|
|
|
|
.. figure:: img/animation_select_audiostreamplayer.png)
|
2022-03-18 17:46:08 +01:00
|
|
|
|
:alt: Select AudioStreamPlayer
|
|
|
|
|
|
|
|
|
|
Select AudioStreamPlayer
|
|
|
|
|
|
|
|
|
|
Right click the timeline where Godot should play the sample and
|
|
|
|
|
click the "Insert Key" option. This will bring up a list of methods
|
|
|
|
|
that can be called for the AudioStreamPlayer node. Select the first
|
|
|
|
|
one.
|
|
|
|
|
|
2023-01-12 20:16:00 +01:00
|
|
|
|
![](img/animation_method_options.png)
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
|
|
When Godot reaches the keyframe, Godot calls the
|
2023-01-12 19:32:38 +01:00
|
|
|
|
`AudioStreamPlayer` node's "play" function and the stream
|
2022-03-18 17:46:08 +01:00
|
|
|
|
plays.
|
|
|
|
|
|
|
|
|
|
You can change its position by dragging it on the timeline, you can also
|
|
|
|
|
click on the keyframe and use the keyframe settings in the inspector.
|
|
|
|
|
|
2023-01-12 20:16:00 +01:00
|
|
|
|
![](img/animation_call_method_keyframe.png)
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
2023-01-12 20:16:00 +01:00
|
|
|
|
.. |Play from beginning| image:: img/animation_play_from_beginning.png)
|
|
|
|
|
.. |Add Animation| image:: img/animation_add.png)
|
|
|
|
|
.. |Add track| image:: img/animation_add_track.png)
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
|
|
Using RESET tracks
|
|
|
|
|
------------------
|
|
|
|
|
|
|
|
|
|
You can set up a special *RESET* animation to contain the "default pose".
|
|
|
|
|
This is used to ensure that the default pose is restored when you save
|
|
|
|
|
the scene and open it again in the editor.
|
|
|
|
|
|
|
|
|
|
For existing tracks, you can add an animation called "RESET" (case-sensitive),
|
|
|
|
|
then add tracks for each property that you want to reset.
|
|
|
|
|
The only keyframe should be at time 0, and give it the desired default value
|
|
|
|
|
for each track.
|
|
|
|
|
|
2023-01-12 19:43:03 +01:00
|
|
|
|
If AnimationPlayer's **Reset On Save** property is set to `true`,
|
2022-03-18 17:46:08 +01:00
|
|
|
|
the scene will be saved with the effects of the reset animation applied
|
2023-01-12 19:43:03 +01:00
|
|
|
|
(as if it had been seeked to time `0.0`).
|
2022-03-18 17:46:08 +01:00
|
|
|
|
This only affects the saved file – the property tracks in the editor stay
|
|
|
|
|
where they were.
|
|
|
|
|
|
|
|
|
|
If you want to reset the tracks in the editor, select the AnimationPlayer node,
|
|
|
|
|
open the **Animation** bottom panel then choose **Apply Reset** in the
|
|
|
|
|
animation editor's **Animation** dropdown menu.
|
|
|
|
|
|
|
|
|
|
When adding tracks on new animations, the editor will ask you to automatically
|
|
|
|
|
create a RESET track when using the keyframe icon next to a property in the inspector.
|
|
|
|
|
This does not apply on tracks created with Godot versions prior to 3.4,
|
|
|
|
|
as the animation reset track feature was added in 3.4.
|