#Need help with State Machine

1 messages · Page 1 of 1 (latest)

vestal kindle
#

I cannot see your States code for your State machine. But I assume you need to make sure you are not transitioning out from JUMP State until you are bacck on the floor#

#

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

stuck anvil
#

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

sour pine
# stuck anvil This is the Idle State script

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.

stuck anvil
#

Ohh

#

I think switching it to an airborne state would be wiser