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

Just started using Construct 2? Post your questions here

Post » Fri Jul 15, 2016 1:23 pm

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
Image
B
28
S
14
G
21
Posts: 179
Reputation: 13,548

Post » Fri Jul 15, 2016 2:08 pm

It does enter fullscreenshooting but you spawn anim_LaserBlast and then immediately destroy it.
ImageImageImage
B
71
S
21
G
230
Posts: 3,688
Reputation: 128,852

Post » Sat Jul 16, 2016 2:54 am

heyguy wrote: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.
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Sat Jul 16, 2016 8:29 pm

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.

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?

Image
B
28
S
14
G
21
Posts: 179
Reputation: 13,548


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 1 guest