#Need help with State Machine
1 messages · Page 1 of 1 (latest)
So, in your JUMP STATE, make sure there is no code that transitions to IDLE if you are NOT on floor.~
And on IDLE state, make sure that will only run if the Player is ON FLOOR
This is the transition function in my state machine
This is the Idle State script
I printed the current state every frame and it shows the jump state only occuring for one frame
I think maybe as soon as the jump state occurs, even with the increase in vertical velocity, godot still counts the player as 'on the floor' so it immediately goes into idle state
The jump state only checks that the button has been pressed and the player is in the floor.
Once you jump, the later condition will inevitably become false.
You could use a counter to keep track of how long the player has been in the air and wait for that to run out before making it enter the fall state.
You can put your current "and" states inside parenthesis and add an extra "or air_time > 4" outside of it.
That way it will enter if either it just tried to jump from the floor OR it has been in the air for a short time.
Personally i'd rethink the state entirely.
In a project of mine i simply have an "Airborne" state that just needs the player to be NOT on the floor.
The jump occurs from the "Idle" or the "Walking" state. After that, the initial burst of velocity does the rest.