All Questions

Community

z
Zoidberg zoidbergforpresident

I don't get it...

At first I had done it in move and changed the is_sprinting boolean in unhandledinput and put it at true only if the key was pushed. That allowed me to calculate the velocity in Move state with either the max speed or maxsprintspeed. But your hint put me off as there isn't any movement code in the children states... Also, if I push the sprint key in idle state then move, the max speed doesn't change...
  • Nathan Lovato replied

    There is movement code happening from the Run state:

    move.physics_process(delta)
    

    You're explicitly asking the parent state to run its physics process from the run state with that line.

    That’s how our Run state extends its parent Move state in practice. You don't want to see them as completely separate classes. We don't use GDScript's extend keyword because using nodes instead has practical advantages, but in the case of our Hierarchical State Machine, you can treat Move as a base node that Run builds upon.

    Then, when you extend a class, you inherit properties that you can modify freely, like e.g. our Move state’s velocity.

    You can directly modify the properties of the Move state from the run script.