0 votes

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:
        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))
        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)

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.

Godot version 3.5
in Engine by (46 points)
reshown by

1 Answer

0 votes
Best answer

Solved by adding a return when I change a state

by (46 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.