Problems setting up a state machine.

0 favourites
  • 5 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.
  • Hello! I'm setting up a state machine here, but I'm having a lot of problems that I can't solve...

    This is the current one:

    The enemy family has 3 states, waiting, searching, and attacking. When he is attacking the "create object EnemyAttackFx" creates like 60 sprites instead of only one. And only creates them on top of one enemy and not on every enemy of the family that is in that state.

    Here is the script:

    I already try a lot of things but I'm a bit lost. Also, if anybody has a state machine tip to follow It would be great! I also have the problem of having only one member of the family doing another kind of stuff, but that's probably part of the same problem.

    Thanks for the help!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 'is attack running' runs constantly and you probably don't need it. Also the every 1 seconds seems unnecessary.

    I would start by adding the timer for 'Waiting' not a system wait. Then you can say on Waiting timer finished, if you are within distance, run the create object attack and then start the Waiting timer again, you don't need this state variable for attack tbh.

    If you are not within distance then you can run a 'Searching' timer, I'm not sure what that means for the enemy but you can say on Search timer finished start the Waiting timer. Everything will then return to this Waiting state.

    Whenever you start a timer you can set the state so you know what's going on. Right now it's looking a little convoluted and will be difficult to control for multiple enemies, but the above will help simplify. Also I would get it working with one instance of enemy before you try looking at multiple enemies.

  • Thanks for the replay! I made it work but not as clean as you told me, probably I'm misunderstanding how some elements work in construct. I'll keep working and learning!

    I'm probably going to make the whole state machine from 0 again and see if I made a mess somewhere. Here is the file in case you want to take a look!

    drive.google.com/file/d/1HMj1g8ZQowhHJZTtY6vTMYzqWF6DK9FW/view

    Thanks for your response!

  • Yep np it's a learning process. I think only one enemy is moving so there is already a problem. Try what I mentioned above it's only a few events and simple.

  • Everything working as a charm! Thanks!

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