How do I Easystar Enemy Movement?

0 favourites
  • 13 posts
From the Asset Store
Be discreet and rescue your friends from behind enemy lines.
  • Hey guys, I'm trying to use Easystar to move around enemies.

    So I have multiple enemies calculating path to the enemy and moving, my problem is that they are calculating path at the same tick, so 2 enemies could move to the same tile after getting path.

    Anyone that have used it know how can I calculate the path one enemy per tick?

    TIA

  • Can you share your code to make it easier to diagnose?

  • Sure, here

  • From your code, you should only have a single enemy finding a path every 0.15 seconds cause you are only picking one instance with the "pick random" condition.

    Your last event could be causing the problems though because it would be setting has_moved to false on the same tick that an enemy is finding a path and setting Has_Moved to true.

    What is the behaviour that you are trying to achieve? Do you want all of your enemies to find a valid path on the same tick?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • From your code, you should only have a single enemy finding a path every 0.15 seconds cause you are only picking one instance with the "pick random" condition.

    Your last event could be causing the problems though because it would be setting has_moved to false on the same tick that an enemy is finding a path and setting Has_Moved to true.

    What is the behaviour that you are trying to achieve? Do you want all of your enemies to find a valid path on the same tick?

    This is actually my last attempt, i tried another ways, using for.. for each.. etc

    What I want to achieve is:

    All enemies should move 1 tile closer to the player like "every 0.5 seconds" all them move to the next square of the path found. And they are moving, what I think that is happening, is all them are calculing the path togheter, and when they try to move, if there are 2 enemies closer, sometimes they try to move to the same tile

  • Ok. You need a way to store the tile that is going to be occupied by each unit that moves and check that against the other units when finding a path. I'm not familiar with EasyStar so I don't know if this is supposed to be built in or not.

    Normally I would flag the position to be moved to with a variable, or a change in tile state, then exclude that from being a valid path for find path events that follow.

    You would do this using loops. I will make a small example when I have more time to show the logic of it.

  • dropbox.com/s/apv49zqadv9rotn/easystartilemove.c3p

    Thanks but it doesnt show the same problem because there are no multiples sprites finding path and moving simultaneos, enemies moving should also "move" the tiles because they are obstacles.

  • I know it doesn't answer your specific question, because it does not use the EasyStar plugin. But here is an example of grid based pathfinding and movement using an Array.

    In the example enemy and player position is updated in the array. Multiple passes of the pathfinding function allow the future position of enemies to be stored and their current positions cleared to make room for other enemies.

    1drv.ms/u/s!AkmrWgxeuxlKhJkKoRmgtGecc7MfVw

    The logic should be able to be applied to other pathfinding implementations.

  • This is normally a pretty difficult task with the official PF behavior. However EasyStar works really fast and doesn't require map recalculations, so it's quite easy to modify the obstacle map for each enemy on every step. Check out this demo:

    dropbox.com/s/kkghcotqlz051nt/TileMovement_PF.c3p

  • This is normally a pretty difficult task with the official PF behavior. However EasyStar works really fast and doesn't require map recalculations, so it's quite easy to modify the obstacle map for each enemy on every step. Check out this demo:

    https://www.dropbox.com/s/kkghcotqlz051nt/TileMovement_PF.c3p?dl=0

    Ohh I see...

    I was moving tiles of the tileset to use as obstacles but it has the options to add and remove obstacles... and force recalculation.. Thanks I will try it, good example!

  • It's probably better to increase tile cost. This will prevent the situation when the path becomes blocked completely:

  • Thanks for the help guys, is way better now, not perfect but way better.

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