0 votes

if I script a top down game and need a separate idle for RIGHT, LEFT, TOP, DOWN how do i set this that i can have the sprite face a certain way after walking then play the different idle animation

in Engine by (27 points)

2 Answers

+1 vote

Use AnimationTree, it's an incredibly powerful feature, the best of any game engine imho.

This node gives you numerous methods for handling animations so it takes a little getting used to but from what you describe I would begin by looking at BlendSpace2D. This is like a grid that allows you to position animation points as coordinates, you can then move between the states in a way that corresponds to your character's direction - which, if I understand you right, is exactly what you're looking for.

Official tutorial here:
https://docs.godotengine.org/en/stable/tutorials/animation/animation_tree.html

Excellent video tutorial here:
https://youtu.be/KAZX4qfD06E

by (1,789 points)

I've tried lots of tutorials on Animation Trees and nothing has worked so far can get the jist of it

0 votes

I do it with an enum for the Animations:

enum ANIMATION {
    WALKDOWN = 0,
    WALKUP = 180,
    WALKX = 90,
    WALKXF = 270,
}

When the Player moves down he is in the WALKDOWN Animation:

if movement.y > 0:
    animation.play("walkdown")
    G.player_animation = ANIMATION.WALKDOWN

Then I say, when he is in this Animation and the movement is Zero, the Player has to Play the Idle-animation:

if G.player_animation == ANIMATION.WALKDOWN and movement == Vector2.ZERO:
    animation.play("idledown")
if G.player_animation == ANIMATION.WALKUP and movement == Vector2.ZERO:
    animation.play("idleup")
if G.player_animation == ANIMATION.WALKX and movement == Vector2.ZERO:
    animation.play("idlex")
if G.player_animation == ANIMATION.WALKXF and movement == Vector2.ZERO:
    animation.play("idlex")

I have the player_animation in a Global script because I need it for Scene changing.

by (22 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.