How do I cycle enemies to have them move one after another?

1 favourites
  • 5 posts
From the Asset Store
Perfect for your zombie game! Animated from motion capture data Left, Right, Top Down!
  • Hi all, quick question.

    I have my enemy movement setup in a couple functions so that they mark the tiles around them as moveable, then move to a random one that is marked. Its working as intended, but I would like to have them move one at a time, or at least staggered enough so that they can set tiles with other enemies as obstacles. One at a time is much preferred, but ill take what I can get.

    I know it'll be with loops but I cant seem to get any configuration working. I have never really worked with loops extensively, so be gentle.

    I feel this should be an easy fix, but have hit a real roadblock.

    Many thanks in advance for any help.

    Tagged:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You actually don't want a loop, since by nature loops will complete within a tick, and thus everything done in the loop would be simultaneous as far as the user can see.

    What you'll want is an incrementing counter, and a way to sort/order the enemies (for further reading search 'state machine').

    Lets say they have instance variable for their turn order, from 0 to n. Use a global variable "currentTurn", starting at 0. So you would pick the instance that matches currentTurn, and have it move. Upon finishing the move, increase currentTurn by 1.

  • Hi all, quick question.

    I have my enemy movement setup in a couple functions so that they mark the tiles around them as moveable, then move to a random one that is marked. Its working as intended, but I would like to have them move one at a time, or at least staggered enough so that they can set tiles with other enemies as obstacles. One at a time is much preferred, but ill take what I can get.

    I know it'll be with loops but I cant seem to get any configuration working. I have never really worked with loops extensively, so be gentle.

    I feel this should be an easy fix, but have hit a real roadblock.

    Many thanks in advance for any help.

    Many ways you can do this as most things in construct, however like he said above using a variable is probably the easiest way. I would use instance variables on the enemies, if enemy Ivariable = 0 - dont move, if 1 move.

    Not 100% sure how you want it tho since i dont have your .c3p, but feel free to add me on discord if u get stuck on something. ironside#6435

  • First want to thank you guys for the help, its finally working. :)

    I now have it so that once its the enemies turn, it orders the enemies buy UID (it will be a speed stat later) then sets their "move_order" independent variable accordingly.

    Next it counts how many their are, so that it can compare that with the current turn number.

    Finally it goes through one at a time in ascending order, and toggles them "active", which in turn triggers the movement system I setup earlier. Then its just a case of adding 1 then comparing the two variables I setup, If it has gone through the same amount of times are there are enemies, it will start my turn.

    Hopefully I can slim down the process by working with this system more. The variables were what I was missing in the end, many thanks!

  • Hello RedJesterStudios

    I'm working on a similar system in which multiple instance move one after the other and I'm interested by your approach but don't understand it very much.

    Would you post a file or a screen cast to make it clearer ?

    Thank you!

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