StateMachinePlayback
- Game Development course
- Expert
- Lesson 27/47
- 4 min
Learn state transitions with StateMachinePlayback.
What is StateMachinePlayback?
StateMachinePlayback is the structure that controls the state machine inside AnimationTree. With the travel() method you transition from one state to another. This structure manages the order and transitions of animations.
playback.travel("kosma")State machine transitions are defined independently from game logic.
Transition rules
Transition rules decide when to move from one state to another. In the AnimationTree editor these rules are defined visually. When travel() is called the state machine follows the most suitable path.
playback.travel("ziplama")Correct transitions make animations look smooth.
Practice Perform a state transition
In a script named GecisKurulumu, assign the $AnimationTree node to a variable named agac in _ready, assign the result of agac.get("parameters/playback") to a variable named playback. Transition with playback.travel("kosma") and print the text "Durum degisti" with print.
Starter code
extends Node
func _ready():
var agac = $AnimationTree
var playback = agac.get("parameters/playback")
# playback uzerinden "kosma" durumuna gecis yap
# "Durum degisti" metnini yazdirSample solution
extends Node
func _ready():
var agac = $AnimationTree
var playback = agac.get("parameters/playback")
playback.travel("kosma")
print("Durum degisti")Expected output
Durum degisti
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What does the travel() method do on StateMachinePlayback?
- It resets all states
- It creates a new animation clip
- It transitions from one state to another Correct answer
- It sets the animation speed
Explanation: The travel() method transitions from the current state to the target state and applies the transition rules in between.
2 Write the transition method
playback.____("kosma")
playback.travel("kosma")
Explanation: In StateMachinePlayback, transitions between states are made with the travel() method.
3 State transition terms
| Term | Meaning |
|---|---|
StateMachinePlayback |
Structure controlling the state machine |
travel() |
Transitions between states |
Status |
An animation phase |
Geçiş kuralı |
Condition deciding when states change |