From a humble stroll to large bosses and fancy UI components, video video games are all about animations! In Godot, you possibly can create animations utilizing the AnimationPlayer node and a versatile animation system permitting you to create your personal animations utilizing a timeline. You may make nodes transfer, change coloration, make sounds or anything over time in Godot.
On this article, you’ll learn the way animations in Godot work and how you can create your personal utilizing the AnimationPlayer node. Right here’s a abstract of what you’ll be taught:
Animate the place and coloration of a sprite
Get conversant in the AnimationPlayer node and the Animation panel
Create a cutout animation
Use different observe varieties to orchestrate animations and play sound results
The top results of this tutorial shall be an animated title card and a robotic arm that drills right into a block.
Getting Began
To get began, obtain the undertaking supplies by way of the Obtain Supplies hyperlink on the high and backside of this web page. Subsequent, import and edit the starter undertaking in Godot.
Foremost Scene
As soon as the undertaking is loaded, you’ll be greeted by the primary scene, which consists of a Background sprite and two hidden nodes for later use: a Robotic Arm and a Block.
For those who run the undertaking, it is best to see simply the background sprite.
File Overview
Now check out the FileSystem tab to see the included assets.
Right here’s an outline of the information and folders:
scenes: Incorporates the primary scene
scripts: There’s a single script right here used to animate the hidden Block node
sounds: This folder holds the drill sound impact for the robotic arm
sprites: All sprites used all through the undertaking, together with the components of the robotic arm and the background
credit score.txt: Credit for the undertaking property
icon.svg: The default icon for the undertaking
Now you’ve got a grasp of what the undertaking appears to be like like, you’re able to know extra in regards to the AnimationPlayer node!
What’s an AnimationPlayer?
The AnimationPlayer node holds animations and means that you can play, pause, and cease them. It could actually manipulate the properties of nodes within the scene and interpolate them over time. For instance, you possibly can transfer a sprite, make characters blink and alter the fabric of a mesh.
This node is among the extra highly effective ones in Godot, and also you’ll discover makes use of for it in virtually each undertaking. Mixed with the Animation panel, the AnimationPlayer node offers you the instruments it is advisable to create your personal animations.
Animation Necessities
To your first animation, you’ll be animating the place and coloration of a title sprite so it strikes into the display screen and fades out.
This may cowl the fundamentals of how you can create an animation from scratch.
Getting ready the Scene
First up, you’ll want the sprite for the title card. Add it to the scene as a baby of the Foremost root node by dragging the title.png from the sprites folder into the viewport.
Choose the brand new Title node this created and alter its place to (X: 630, Y: 160) by way of the Inspector so it’s on the high of the display screen.
With the title in place, you possibly can create an AnimationPlayer node. Go forward and create a brand new AnimationPlayer node as a baby of the Foremost root node. To do that, right-click the foundation node and choose Add Youngster Node… within the context menu.
Subsequent, filter for AnimationPlayer within the search bar on the high and double-click the AnimationPlayer possibility so as to add it to the scene.
To maintain observe of its goal, rename this new AnimationPlayer node TitleAnimationPlayer.Choose the TitleAnimationPlayer node and it is best to see the Animation panel opening on the backside of the editor.
That is the place the magic occurs! Within the subsequent part you’ll be creating the animation itself.
Creating the Animation
Create a brand new animation by clicking the Animation button within the Animation panel and choosing New.
A dialog window will pop up asking for the identify of the animation. Enter title because the identify and click on OK to create the animation.The timeline will now be proven within the area under the Animation button.
The title animation will take 2 seconds to finish, so change the animation size to 2 seconds on the far proper of the animation panel, subsequent to the clock icon.
Including Keyframes
Every thing is now prepared to begin including keyframes. Keyframes are time limits within the animation the place a worth modifications. The animation will interpolate between these keyframes over time.To point out how this works in follow, choose the Title node within the scene and try the Inspector. With the Animation panel opened, you’ll see key buttons subsequent to node properties.
These buttons will add a keyframe to the animation on the present place within the timeline. Click on the keyframe button subsequent to the Place property to present it a shot. After doing so, you’ll see a dialog window asking you if you wish to create a brand new observe and a key.
An animation observe is a set of keyframes. You’ll want a separate observe for every property you wish to animate. That means, you possibly can animate a number of properties on the similar time.
There are two checkboxes right here: Use Bezier Curves and Create RESET Observe(s). The previous will allow bezier curves for the animation observe, which will provide you with handles to regulate the form of the curve to positive tune the animation. The latter will create an additional RESET animation with the identical property observe that can reset the property to its default worth.
You possibly can preserve each checkboxes at their default values right here, as you gained’t be needing bezier curves. Click on Create to create the animation tracks.
Now take one other take a look at the Animation panel. As you possibly can see, there’s a observe now for the Place property of the Title node. There’s additionally a keyframe now initially of the timeline, represented by a diamond form.
A single keyframe gained’t do something, so that you’ll want so as to add one other to create an animation. To take action, you’ll have to set the time the place you need your new keyframe to be added. Transfer the time slider to 0.8 second mark by dragging your cursor on the timeline header (the numbers on the high) or by setting it instantly within the animation place property on the high left. If you wish to see smaller increments on the time header, maintain the CTRL/CMD key and scroll up.