Idle Animation

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By K1ngK0ng

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

:bust_in_silhouette: Reply From: KaWa

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.

:bust_in_silhouette: Reply From: DaddyMonster

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:

Excellent video tutorial here:

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

K1ngK0ng | 2021-11-04 15:33