+1 vote

I hav made a state machine in Animation State Machine but don't know how to set the condition to next state

The state machine is inside a animation tree node, so I need to retrieve the state machine first?

Any ideas?

Thanks

in Engine by (247 points)

1 Answer

+6 votes
Best answer

Assuming AnimationNodeStateMachine is assigned as a root of animation tree:

# Retrieve state machine controller
var playback = $animation_tree.get("parameters/playback")

# Make sure to `Start` a state machine before any transition can occur
playback.start('rest')

# ... code to change state here ...

if walking:
    # Transition to a new state according to defined transition graph
    playback.travel('walk')

if jumping:
    playback.travel('jump')

Animation state machine transition graph

You can stop the animation state machine simply with:

playback.stop()

See the docs for additional info.
Also the official blog post about the new animation system.

by (1,367 points)
selected by
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.