0 votes

i have a few animations attached to my controls so far, as seen in the code below:
if direction.x != 0:
$AnimatedSprite.animation = "leftright"
$AnimatedSprite.flip
v = false
$AnimatedSprite.fliph = direction.x < 0
elif direction.y < 0:
$AnimatedSprite.animation = "up"
elif direction.y > 0:
$AnimatedSprite.animation = "down"
each of these animations uses a few frames. i was planning on setting the idle state to one of the frames in the animations, but i'm not sure how. i don't know if i would use cords like i did before or if i would use some type of command where the input to control my character is released, causing it to go to a certain frame with the command "set
sprite_frames(value)". I'm not too sure how to work this out since i'm new to the godot engine, so if anyone could give me some pointers it would be greatly appreciated.

in Engine by (16 points)

1 Answer

0 votes

I would do a state machine and then cycle through those. I am working on a 2d character that has run, walk and idle animations.

enum STATE {IDLE, WALKING, RUNNING}
var playerState = STATE.IDLE

func _process(delta):
     match playerState:
           STATE.IDLE:
                # idle command/animation here
           STATE.WALKING:
                # walking
           STATE.RUNNING:
                # running

You can add however many states you want then use whatever logic you prefer to change the Player state as necessary. You can also run the match logic in different functions to keep your animations/commands decoupled (which I'd recommend for your own sanity).

by (534 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 Frequently asked questions and 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 [email protected] with your username.