Varied Pathfinding

1 favourites
From the Asset Store
Units do not overlap each other and use different ways if there are several free ways.
  • I'm looking for a way to make pathfinding more varied... When a group of objects find a path toward a target, they'll all take the same route and travel in a straight line - is there a way to make some of them go slightly off the path or even a different way entirely?

    Since I'm making an automatic spawner for a lot of the same object, I can't individually assign different paths to a certain sprite through the editor, it'll have to be done through the code. Thanks in advance!

  • bump ^^ !

  • The pathfinding calculates the shortest route each time. If I was to do this I would create obstacles before calculating the path to alter which way they go. You could create a number of set routes by blocking certain directions.

  • This is actually an incredibly difficult problem. It's essentially crowd control and it quickly becomes highly chaotic and CPU-intensive, and easy to end up with objects getting permanently stuck. I've tried and failed to do this in a robust way in the past, I'm not sure what the best approach is.

  • If you move several of them at the time try to pick one as "leading unit" that uses pathfinding and others to follow "leader" at certain distance and angles... like "flocking" - wich is more like a formation movement.

    Or try to add one or several mid destination points and set unit to randomly pick second as it reaches the first?

  • I was thinking of something :

    • Put on your scene a few invisible obstacles that you can activate/desactivate.
    • Every time an object has to find its path, chose randomly a random number of obstacles to activate. This will create for every object a different path to choose from. One path is calculated, disable active obstacle and apply the same process to the next object
    • Of course, you'll have to place your invisible obstacles on stage so that they won't create dead end where an object can be stuck.

    I didn't give it a try but this may be worth trying

  • I was thinking of something :

    - Put on your scene a few invisible obstacles that you can activate/desactivate.

    - Every time an object has to find its path, chose randomly a random number of obstacles to activate. This will create for every object a different path to choose from. One path is calculated, disable active obstacle and apply the same process to the next object

    - Of course, you'll have to place your invisible obstacles on stage so that they won't create dead end where an object can be stuck.

    I didn't give it a try but this may be worth trying

    Yes that's what I was saying above. I've put it into practice and it works.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • > I was thinking of something :

    > - Put on your scene a few invisible obstacles that you can activate/desactivate.

    > - Every time an object has to find its path, chose randomly a random number of obstacles to activate. This will create for every object a different path to choose from. One path is calculated, disable active obstacle and apply the same process to the next object

    > - Of course, you'll have to place your invisible obstacles on stage so that they won't create dead end where an object can be stuck.

    >

    > I didn't give it a try but this may be worth trying

    >

    Yes that's what I was saying above. I've put it into practice and it works.

    Oh ! Sorry, it seems I missed your post.

    Do you have a capx to see how you achieved this ?

  • I was thinking of something :

    - Put on your scene a few invisible obstacles that you can activate/desactivate.

    - Every time an object has to find its path, chose randomly a random number of obstacles to activate. This will create for every object a different path to choose from. One path is calculated, disable active obstacle and apply the same process to the next object

    - Of course, you'll have to place your invisible obstacles on stage so that they won't create dead end where an object can be stuck.

    I didn't give it a try but this may be worth trying

    Having trouble doing this... After assigning a round(random) number to the pathfinding object on creation, I add obstacles to it depending on what number it was assigned and then find a path. After finding the path it just goes straight through everything toward the destination :/ Any ideas?

  • I think you should check if you have added a Solid behavior to your obstacles and make sure Solids are assigned as obstacles in the Pathfinding behavior.

    The random numbers that are generated will determine witch obstacle's solid behavior will be turn from Inactive to Active.

    There is something you can do :

    • put obstacles on your stage
    • design different (let's say, 5) possible paths that are determined by a different combinaison of obstacles. Put the corresponding set of obstacles in different families named (for exemple) pathObstacle1, pathObstacle2, pathObstacle3...
    • for every moving object, before path is calculated, select a random family and put it as an obstacle in the Pathfinding behavior
    • calculate path

    Should be something like that :

    + System: For each MovingObject

    -> MovingObject: Add Pathfinding obstacle Obstacle(random(1,5))

    -> MovingObject: Find path to (targetx, targety)

  • I think you should check if you have added a Solid behavior to your obstacles and make sure Solids are assigned as obstacles in the Pathfinding behavior.

    The random numbers that are generated will determine witch obstacle's solid behavior will be turn from Inactive to Active.

    There is something you can do :

    - put obstacles on your stage

    - design different (let's say, 5) possible paths that are determined by a different combinaison of obstacles. Put the corresponding set of obstacles in different families named (for exemple) pathObstacle1, pathObstacle2, pathObstacle3...

    - for every moving object, before path is calculated, select a random family and put it as an obstacle in the Pathfinding behavior

    - calculate path

    Should be something like that :

    + System: For each MovingObject

    -> MovingObject: Add Pathfinding obstacle Obstacle(random(1,5))

    -> MovingObject: Find path to (targetx, targety)

    The problem with making obstacles solid is that then the player can't get past those obstacles - also the walls tilemap (which is solid), when added as an obstacle after creation, doesn't work either and the object paths right through it

  • > I was thinking of something :

    > - Put on your scene a few invisible obstacles that you can activate/desactivate.

    > - Every time an object has to find its path, chose randomly a random number of obstacles to activate. This will create for every object a different path to choose from. One path is calculated, disable active obstacle and apply the same process to the next object

    > - Of course, you'll have to place your invisible obstacles on stage so that they won't create dead end where an object can be stuck.

    >

    > I didn't give it a try but this may be worth trying

    >

    Having trouble doing this... After assigning a round(random) number to the pathfinding object on creation, I add obstacles to it depending on what number it was assigned and then find a path. After finding the path it just goes straight through everything toward the destination :/ Any ideas?

    Whenever the obstacles change you need to regenerate obstacle map.

  • > I think you should check if you have added a Solid behavior to your obstacles and make sure Solids are assigned as obstacles in the Pathfinding behavior.

    > The random numbers that are generated will determine witch obstacle's solid behavior will be turn from Inactive to Active.

    >

    > There is something you can do :

    > - put obstacles on your stage

    > - design different (let's say, 5) possible paths that are determined by a different combinaison of obstacles. Put the corresponding set of obstacles in different families named (for exemple) pathObstacle1, pathObstacle2, pathObstacle3...

    > - for every moving object, before path is calculated, select a random family and put it as an obstacle in the Pathfinding behavior

    > - calculate path

    >

    > Should be something like that :

    > + System: For each MovingObject

    > -> MovingObject: Add Pathfinding obstacle Obstacle(random(1,5))

    > -> MovingObject: Find path to (targetx, targety)

    >

    The problem with making obstacles solid is that then the player can't get past those obstacles - also the walls tilemap (which is solid), when added as an obstacle after creation, doesn't work either and the object paths right through it

    Just disable obstacles once path is calculated.

    Sequence is :

    • Activate random set of obstacle
    • regenerate obstacle map
    • calculate path
    • deactivate set of obstacle
    • move along path
  • Isn't regenerating the obstacle map for a new object every second going to be incredibly CPU intensive?

  • Who is that in response to? Yes it would be but nobody suggested to do that.

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