Why is my state machine not working?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Moot Point

Hi, I have a simple state machine with only two states for now and the transition seems to be broken and I don’t know why

	match cur_state:
	IDLE:
		if input_vector != Vector3.ZERO:
			cur_state = WALK

			
		tree.set("parameters/Attack/blend_position", Vector3(sideways, forwards, 0))
		tree.set("parameters/Idle/blend_position", Vector3(sideways, forwards, 0))
		state.travel("Idle")
	WALK:
		if input_vector == Vector3.ZERO:
			cur_state = IDLE
		
		idle_direction = Vector3(move_direction.x, 0, move_direction.z)
		tree.set("parameters/Walk/blend_position", input_vector)
		state.travel("Walk")

I’m using an animation tree to blend an 8 way sprite in a 3D game relative to the camera when it’s in IDLE state, and just use inputs as blend position in walking state.
I have my base state to be IDLE and it works, it rotates correctly but when I change to WALK and then back to IDLE the character locks at looking at the camera.

I tried to change states outside the state machine, checking if input_vector was equal to ZERO and it actually worked, but it defeats the whole purpose of doing it like this anyways.

Forwards and sideways are just dot products of camera and character direction to see where the blend tree should be. The calculations for it are in the update so it should always be updated but when I change back to IDLE it just locks.

:bust_in_silhouette: Reply From: Moot Point

Solved by adding a return when I change a state