How do i make my character play a walking animation when it moves?

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

I’m trying to make my character play a walking animation when its moving, but it only plays when i’m jumping and it gives me a lot of errors.

I’m fairly new with GDScript so cut me some slack.

Here’s my code:

if walking == 1:
play_anim(“walk”)

if Vector3.AXIS_X or Vector3.AXIS_Z > 1:
	walking = 1
else:
	walking = 0

Don’t worry about it, that’s what this site is all about.
But, the formatting of the code you posted is a little bit awry, so it’s a little hard to tell, but does your code look something like this? :

var walking = 0

.....

if walking == 1:
play_anim("walk")
if Vector3.AXIS_X or Vector3.AXIS_Z > 1:
walking = 1
else:
walking = 0

Or does it look like this? :

if walking == 1:
play_anim("walk")

if Vector3.AXIS_X or Vector3.AXIS_Z > 1:
walking = 1
else:
walking = 0

The identation is important to know, because if it’s the first option then your walking variable is never set to 1, and so you would have no movement.

And if it’s the second case… it would be great to see what the jump code is as well.

Yuminous | 2021-07-23 04:05

:bust_in_silhouette: Reply From: umma

this is the easier way to go

extends kinematicbody

onready var walking = $animationplayer

func _ready():
if Input.is_action_pressed(“ui_up”) and Vector3.AXIS_X or Vector3.AXIS_Z > 1:
walking.play(“walk_animation”)
else:
walking.stop()