iconSUPERMATRIX STUDIO
HomeProjectsAboutBlogNewsLatest Project
  1. Home
  2. Blog
  3. Step by step guide to 2d character animation in godot 4
Step-by-Step Guide to 2D Character Animation in Godot 4

Step-by-Step Guide to 2D Character Animation in Godot 4

By cyberdevz on September 14, 2025

Tags:#Godot 4#2D Animation#Game Dev#Pixel Art#Tutorial

Table of Contents#

  • Introduction: Breathing Life into Pixels
  • Step 1: Setting Up Your Character Scene
  • Step 2: Meet the AnimationPlayer - Your Digital Flipbook
  • Step 3: Creating an "Idle" Animation
  • Step 4: Building a Multi-Frame "Run" Animation
  • Step 5: Triggering Animations with GDScript
  • Conclusion: Animation is More Than Just Sprites

Introduction: Breathing Life into Pixels #

A static character is just an image, but an animated character has a personality. In Godot 4, one of the most essential tools for bringing your 2D characters to life is the AnimationPlayer node. While its name sounds simple, it's an incredibly versatile tool that can animate any property of any node, from a sprite's frame to its position, color, or even the volume of a sound effect.

In this guide, we'll demystify the AnimationPlayer by creating two fundamental character animations: idle and run. You'll learn how to set up your scene, create keyframes, and trigger your animations with code. Let's get started!


Step 1: Setting Up Your Character Scene #

First, we need a character to animate. A standard setup for a 2D player character in Godot consists of a few key nodes.

Create a new scene with the following structure:

  • CharacterBody2D (The root node, for physics and movement)
    • Sprite2D (This will display our character's graphics)
    • CollisionShape2D (Defines the character's hitbox)
    • AnimationPlayer (The node that will handle all our animations)

For your Sprite2D node, you'll need a sprite sheet—a single image file containing all the frames of your character's animations. For this tutorial, we'll assume you have one with frames for an idle and a run cycle. In the Inspector for the Sprite2D, load your sprite sheet into the Texture property.


Step 2: Meet the AnimationPlayer - Your Digital Flipbook #

Select the AnimationPlayer node, and you'll see the Animation panel appear at the bottom of the editor. This is your main workspace.

  1. Create a New Animation: Click the "Animation" button in the panel and select "New". Name it idle.
  2. Set the Length: To the right of the animation name, you can set the animation's duration in seconds. For a simple idle, 1 second is fine.
  3. Enable Looping: To make the animation repeat, click the "Animation Looping" icon (it looks like a circular arrow).

You've now created an empty animation track, ready to be filled with keyframes.


Step 3: Creating an "Idle" Animation #

Let's make our character breathe or blink. For this, we'll animate the Frame property of our Sprite2D node.

  1. Select the Sprite2D node. In the Inspector, go to the Animation section and set the Hframes and Vframes properties to match your sprite sheet's grid. For example, if your sheet is 4 frames across and 2 down, set Hframes to 4 and Vframes to 2.
  2. With the AnimationPlayer panel open and the idle animation selected, find the Frame property in the Sprite2D's Inspector.
  3. Click the key icon next to the Frame property. This adds a keyframe at the current time (0.0) on the timeline. Let's say the first idle frame is frame 0.
  4. Move the timeline scrubber to 0.5 seconds. Change the Frame property to 1 (assuming this is your second idle frame) and click the key icon again.
  5. Press Play in the Animation panel to see your character's subtle idle animation!

Step 4: Building a Multi-Frame "Run" Animation #

Now for something more dynamic. Let's create a new animation called run.

  1. In the Animation panel, click Animation > New and name it run. Set its length (e.g., 0.6 seconds for a 6-frame run) and enable looping.
  2. Ensure the timeline scrubber is at 0.0. Select your Sprite2D, set its Frame property to the first frame of your run cycle (e.g., frame 4), and click the key icon.
  3. Move the scrubber to 0.1, change the Frame to 5, and add a key.
  4. Move the scrubber to 0.2, change the Frame to 6, and add a key.
  5. Continue this pattern until all your run frames are keyframed.

For smoother workflow, you can change the "Track Update Mode" (the dotted icon next to the track name) to Discrete, which is ideal for frame-by-frame sprite changes.


Step 5: Triggering Animations with GDScript #

Animations are useless if they don't play at the right time. Let's add a simple script to our CharacterBody2D root node to control the animations.

Create a new script and attach it. Here's a basic example:

gdscript
extends CharacterBody2D
 
# Get a reference to the AnimationPlayer node
@onready var animation_player = $AnimationPlayer
 
func _physics_process(delta):
    # A simple check: if the character is moving, play 'run'.
    # Otherwise, play 'idle'.
    if velocity.length() > 0:
        animation_player.play("run")
    else:
        animation_player.play("idle")
 
    # (Your movement code for getting input and using move_and_slide() would go here)
    # ...

This script checks the character's velocity on each physics frame. If the character has any speed, it plays the "run" animation. If the character is standing still, it switches to the "idle" animation.


Conclusion: Animation is More Than Just Sprites #

You've successfully created and implemented two essential 2D animations! You now have a solid foundation for bringing any character to life.

Remember, the AnimationPlayer is not limited to sprite frames. Experiment with keyframing other properties:

  • Animate the Position or Scale for a bouncy jump effect.
  • Animate the Modulate property to make a character flash when taking damage.
  • Animate a PointLight2D's energy to make a torch flicker.

The possibilities are endless. Keep experimenting, and soon you'll be creating fluid, expressive characters for your games.

Supermatrix Studio

Building immersive, neon-drenched worlds.

Social
TwitterInstagramYouTubeLinkedIn
© 2025 Supermatrix Studio. All rights reserved.