How do I properly code enemy pattern loops ?

0 favourites
  • 4 posts
From the Asset Store
Give Sound to the enemies that are part of your game! :)
  • I programmed an attack behavior for an enemy but for some reason I couldn't find yet, he goes through the intended loop a couple times and then stops working.

    Each instance has a "timer" value, that is added to the actual timer once they enter in neutral state. Then, after the timer reaches zero, they attack. after finishing the spit animation, they enter in neutral state again, the timer is replenished and the loop starts over.

    Or so I planned, as I said in the beginning, it successfully loops just one or two times before it stops working.

    Here is the code.:

    If anyone can help me with this, thanks in advance.

  • You'll probably find that it works fine with just one instance of the enemy. When you add multiple enemies this starts causing problems because it requires a different kind of picking logic and the trigger once events also cause some confusion, you can't just say 'enemy' you have to specify which enemy.

    You can try 'for each enemy' to see if that works but even this can become buggy if you have a lot of complexity to the enemy patterns, I prefer a more solid way where I use functions, pass the instance UID through the function so I know I am applying it to that enemy. I had logic similar to yours making use of states and timers, skeletons that would charge into a wall, crash and then get up and continue charging, I had many working in one room with no problems using my method.

  • I have a hunch "Trigger Once" is the problem. From my experience "Trigger Once" doesn't work very well when there's multiple instances. Try to figure out a way to solve the problem without it.

    You can start here:


    So on and so forth until all the "Trigger Once" conditions are gone.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks for the tips guys, I changed the bits pointed out and it works fine now!

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