How to make walking animation.

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

So I have recently (literally this morning) gotten back into coding. I have a little experience with Lua, and I wanted to try out Godot. I’m making a walking animation and I have no idea how to do that. I have been looking for hours. Any help is appreciated!

if Input.is_action_pressed("move_up"):
	vel.y -= 1
	facingDir = Vector2(0, -1)
	$LilBoiTexture.texture = load("res://LilBoiAssets/LilBoiBackward.png")
	
	$LilBoiTexture.texture = load("res://LilBoiAssets/LilBoiBackward2.png")

this is what I have so far :smiley:

:bust_in_silhouette: Reply From: RakuNana

I recommend taking a look at the Godot docs, They have a tutorial of exactly what you’re looking for :slight_smile:

I found this but I’m running into an issue where I don’t know how to stop the animation. Or rather where to stop it.

	# inputs
if Input.is_action_pressed("move_up"):
	vel.y -= 1
	facingDir = Vector2(0, -1)
	$LilBoiSprite.play("WalkBack")

	
if Input.is_action_pressed("move_down"):
	vel.y += 1
	facingDir = Vector2(0, 1)
	$LilBoiSprite.play("WalkFor")

	
if Input.is_action_pressed("move_left"):
	vel.x -= 1
	facingDir = Vector2(-1, 0)
	$LilBoiSprite.play("WalkLeft")

	
if Input.is_action_pressed("move_right"):
	vel.x += 1
	facingDir = Vector2(1, 0)
	$LilBoiSprite.play("WalkRight")

I dont know where to put the $animationsprite.stop()

Silent Program | 2020-09-20 02:59

:bust_in_silhouette: Reply From: RakuNana

Simple :slight_smile: create an “else:” statement at the bottom of your if statements. Your code should look like this:

if Input.is_action_pressed("move_up"):
    vel.y -= 1
    facingDir = Vector2(0, -1)
    $LilBoiSprite.play("WalkBack")


if Input.is_action_pressed("move_down"):
    vel.y += 1
    facingDir = Vector2(0, 1)
    $LilBoiSprite.play("WalkFor")


if Input.is_action_pressed("move_left"):
    vel.x -= 1
    facingDir = Vector2(-1, 0)
    $LilBoiSprite.play("WalkLeft")


if Input.is_action_pressed("move_right"):
    vel.x += 1
    facingDir = Vector2(1, 0)
    $LilBoiSprite.play("WalkRight")

else:
    $animationplayer.stop()

so what your code is saying is " if whatever input I pressed is true, play animation.
otherwise if I’m not pressing an input, stop my animation."

Also I recommend changing your other “if” statements under your first “if” statement to "elif instead. This will allow your code to override your previous button presses and keep your animations from not playing properly. Hope That solved your problem! :slight_smile:

Whoops, meant to hit the comment button, sorry about that.

RakuNana | 2020-09-20 05:40