How do I correctly switch states in a finite state machine?

0 favourites
  • 4 posts
From the Asset Store
State Machine
$10.99 USD
State Machine is a great tool for managing the state of anything in your game.
  • Just lost all my post info so I'll make this quick. I'm experimenting with a finite state machine for a side scroller game. Seems to work right expect one part. The boss won't switch from "shooting" to "fullscreenshooting". The basic AI boss pattern would be the boss switching back and forth from "shooting" to "fullscreenshooting" until it had 30 or less health, then it would enter "multishooting" until death. I'd like to throw one more state into the shuffle but I have to figure out what's preventing "fullscreenshooting" from playing. "fullscreenshooting" is a energy semi-circular blast animation that goes down to up .The boss "eye" freezes after the 5 seconds of "shooting" state and does't play the semi-circle animation. I can lower the health enough to play "multshooting" though.

    Can anyone take a look at my capx and spot what's creating this issue. I imagine it's a syntax error. Also, notice when the boss enters "multishooting", the boss sprite rotates. Not sure what that is about. Any advice one what to do about that weird bug? Thanks for looking at my post!

    edit:edit: Oh, one more thing, how do I get boss behavior to run only once, when the player reaches the boss. Trigger once event?

    https://www.dropbox.com/s/sf5exqoab238l ... .capx?dl=0

  • It does enter fullscreenshooting but you spawn anim_LaserBlast and then immediately destroy it.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • edit:edit: Oh, one more thing, how do I get boss behavior to run only once, when the player reaches the boss. Trigger once event?

    Trigger once is one option.

    A second would be to call a function with the behavior desired as an action when you change states.

    Trigger one would be good if you wanted it to happen again if the boss ever left that state and return.

    A function would be good if you wanted to call it in other situations/triggers on demand as well.

  • [quote:26e71bq6]t does enter fullscreenshooting but you spawn anim_LaserBlast and then immediately destroy it.

    Thanks so much blackhornet! That was a simple fix! I added a wait before the destroy. Can't believe I let that slip. Finite state machines seem so awesome! Now I just have to work on all the timings of this attacks so it doesn't look so quick and sloppy and seem like the states are overlapping with each other.

    [quote:26e71bq6]Trigger once is one option.

    A second would be to call a function with the behavior desired as an action when you change states.

    Trigger one would be good if you wanted it to happen again if the boss ever left that state and return.

    A function would be good if you wanted to call it in other situations/triggers on demand as well.

    Got it! Thanks for the explanation. I think in this situation with the code I've already created, a trigger once would work best. Maybe I make an invisible collider the player has no way avoiding that calls that triggers the AI behavior. I need to go over functions again to understand how I could incorporate this boss as a function to be called.

    I have another problem on this capx I forgot to mention before. For some reason, the Boss Eye rotates counter clockwise when its shot and it enters the "multishooting" state . Not sure what that is about. Here's the code. Nothing says rotate counter clockwise 90 degrees and then start attacking. Does anyone know why this might be?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)