Godot Version
Godot 4.2.1
Question
Hi, I’m trying to implement a state machine, and I can’t seem to get it to work. Here’s the tree:
and here’s the relevant code:
func _ready():
state_machine = anim_tree.get("parameters/playback")
func _process(delta):
velocity = Vector3.ZERO
#AI
#IDLE
#Idle Start
if state == ST_IDLESTART:
state_machine.travel("idle")
timer_max = rng.randi_range(120,240)
if timer < timer_max:
timer += 1
elif timer >= timer_max:
turn_goal = rng.randi_range(1,180)
#turn_dir = rng.randi_range(0,1)
turn_dir = DIR_RIGHT
state = ST_IDLETURN
#Idle Turn
elif state == ST_IDLETURN:
#Find which direction to turn
if turn_dir == DIR_RIGHT:
state_machine.travel("turn_right_walk")
if state_machine.get_current_node() == "turn_right_walk":
rotation.y -= 0.01
turn_num += 1
if turn_num >= turn_goal:
state_machine.travel("walk")
state = ST_IDLEWALK
#IdleWalk
elif state == ST_IDLEWALK:
global_transform.origin -= transform.basis.z.normalized() * SPEED * delta
The issue I’m having is that the enemy will reach the “Turn Right” Blend Tree, which is just the Turn Right animation slowed down by 0.5, and then won’t progress any further. But if I remove everything after “turn_right_walk”, then it gets to “turn_right_walk” no problem, which seems weird as the travel function sending the enemy to “turn_right_walk” isn’t changed at all between the two iterations.
Any help is greatly appreciated. Thanks!