1. Tibi

    Let’s say I have 3 states: “Idle”, “Walking” and “Falling”. And a grounded flag which says if i am on the ground or not (recalculated once every FixedUpdate).

    if (Input.moveX > 0.3) TransitionTo(“Walking”)

    if (Input.moveX <= 0.3) TransitionTo("Idle")
    else { }

    if (grounded) TransitionTo(“Idle”)

    Let’s say i am currently in “Falling” (and holding my Input.moveX > 0.3 so when I land i immediately start walking) and after a few FixedUpdates I land on something and my “grounded” flag gets set to true and the current state gets changed to “Idle”.. but I don’t immediately start walking because this is still the FixedUpdate of the “Falling” state.
    So the next FixedUpdate runs and the current state is “Idle” and Input.moveX > 0.3 so the state changes to “Walking”.. but I’m still not moving because this is the FixedUpdate of the “Idle” state.
    So only when the next FixedUpdate runs I start moving.

    But for 3 FixedUpdates I just stand there waiting for the transition conditions to process so I can get to my “Walk” state and start actually moving. I actually tried this and it has a visible glitchy effect.

    Am I missing something? Am I doing this wrong?

    • You probably are right. I’ve written this code about 2 years ago and haven’t touched it ever since to be honest :). You could add another transition from “Falling” to “Walking” but if the code takes 1 frame to advance to a state and execute it you would have managed to reduce the processing from 3 to 1 frame which is not ideal. If I remember correctly this was happening in my case as well (not sure if I coded it like that on purpose or if it’s a bug). I guess you’ll have to tweak the code (or write a new FSM) to switch to the desirable state as soon as the conditions are met. That’s what I’ll be doing at least as I need to write an FSM for another project.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.