0 votes

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
Godot version v3.3.2.stable.flathub
in Engine by (12 points)

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.

1 Answer

0 votes

this is the easier way to go

extends kinematicbody

onready var walking = $animationplayer

func ready():
if Input.is
actionpressed("uiup") and Vector3.AXISX or Vector3.AXISZ > 1:
walking.play("walk_animation")
else:
walking.stop()

by (70 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.