State Machine works on one Unit at at time, not simultaneouly, conflict with "pathfinding"

Not favoritedFavorited Favorited 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.
  • I'm working on a simple, mostly automated RTS.

    I'm using a state machine to handle the units, and even though on debug I see that the states are changing correctly in real time, I can't get the units to act accordingly. The game seems to pick one, complete its pathfinding task, and only then moves to another.

    If I don't use pathfinding, I use "move to" instead, it works as intended, without the pathfinding of course (MoveTo: Move along Pathfinding path yields the same results as moving with pathfinding)

    I didn´t find any solutions on the manual, maybe I´m overlooking something obvious, any help would be appreciated.

    the project:

    https://drive.google.com/file/d/1K8_Ay0JzGBEGJAj9iMziTP0gxKK5im9V/view?usp=sharing

    //DEACTIVATING "FOR EACH" MAKES THEM WORK SIMULTANEOUSLY, BUT THEY APPEAR TO GRAB THE UnitsA.TargetUID VARIABLE FROM ANY UNIT A, NOT THEMSELVES//

    + System: For each UnitsA ===>

    ----+ UnitsA: State = "idle"

    --------+ Sprites_Units: Pick instance with UID UnitsA.SpriteUID

    ---------> UnitsA: Pathfinding: Stop

    ---------> Sprites_Units: Set animation to "idle" (play from current frame)

    ----+ UnitsA: State = "attack"

    --------+ Sprites_Units: Pick instance with UID UnitsA.SpriteUID

    ---------> UnitsA: Pathfinding: Stop

    ---------> Sprites_Units: Set animation to "attack" (play from current frame)

    ----+ UnitsA: State = "chase"

    --------+ Sprites_Units: Pick instance with UID UnitsA.SpriteUID

    ---------> Sprites_Units: Set animation to "move" (play from current frame)

    --------+ System: Every 0.2 seconds

    --------+ UnitsB: Pick instance with UID UnitsA.TargetUID

    ------------+ (no conditions)

    -------------> UnitsA: Pathfinding: Find path to (UnitsB.X, UnitsB.Y)

    + UnitsA: On Pathfinding path found

    -> UnitsA: Pathfinding: Move along path

  • Looks like some weirdness with using every X seconds and for each. I would try something safer like state = chase and unit is not moving along path, then find path. This removes every tick and every X seconds with pathfinding. Also there might be a better way to do your units that what I'm seeing with the two identical families, the picking looks really convoluted. In a game like that you may want to keep Enemies as a separate family to Friendly units. And the extra layer of confusion with spriteUID variable, it seems like there could be a simpler way.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hi! You are right! the every tick was the trouble-maker. Thanks for the reply!

    I added a boolean that Pathfinding needs to check that it´s set before it acts, and turns it off right after. then it turns on every x seconds.

    I get what you are saying about "state = chase and unit is not moving along path, then find path." but I fear that this wont refresh the pathfinding if the target moves right?

    The unitA/unitB is a hack solution to make sure all units share stats, vairables and behaviours, all info is in UnitsA, and Units be is for reference, I saw it in a tutorial as an easy way to reference something in the same group and not risking construct3 mixing target and origin, it was a bit messy at first, but I used it a lot in a previous project and i worked like a charm once i got the hang of it! Thanks for the warning any way, you never now when you might be going down a rabbit hole haha

  • Yeah you are right this would have to reach the original destination and wouldn't keep checkingif that's what you need. You could use the timer behaviour on the unit which I find is always better than system every X seconds, 'on timer finished' you can check certain things then start the timer again for individual units.

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