Hello, I'm testing a state machine on Dodge the creep project. I can not properly change state by checking if the player is or is not moving by using velocity.x/z . Once it got to move state it will not go to Idle state even if I don't have any movement. This is the Print test after releasing input button for jump ("jump" > "idle" > "move")
states.idle
if !parent.is_on_floor():
return states.jump
elif parent.velocity.x !=0 and parent.velocity.z !=0:
return states.move
states.move:
if !parent.is_on_floor():
return states.jump
elif parent.velocity.x ==0 and parent.velocity.z ==0:
return states.idle
states.jump:
if parent.is_on_floor():
return states.idle
So there is something wrong with checking of movement by velocity.x/z. Any suggestion?
ps. code for movements is
if Input.is_action_pressed("move_right"):
direction.x += 1
...
if direction != Vector3.ZERO:
direction = direction.normalized()
velocity.x = direction.x * speed
velocity.z = direction.z * speed
velocity = move_and_slide(velocity, Vector3.UP)