How do I Get Pathfinding to work

1 favourites
  • 4 posts
From the Asset Store
Units do not overlap each other and use different ways if there are several free ways.
  • I'm trying to make a Pacman like game and I can't get the "ghosts" to path find with obstacles or to even work properly.

    Here is my work so far drive.google.com/open me know if that link doesn't work),

    Is there something I'm doing wrong or am I forgetting something? I'm sort of new to this and still learning the layout of Construct 2, so and any help is appreciated.

  • You are using the path finding a bit wrong.

    The way you can think of the path finding behaviour is by following these steps:

    1. Find path

    2. Path found -> Move along path

    3. Path not found -> do something else, could be to try to find a new path or whatever.

    Find path

    This is something that is handle in the background of C2 so your game will actually continue running while the path is found (calculated)

    Therefore you would normally use the "Find path" based on some conditions, like a unit having reached its destination and needing a new path or you could make it trigger based on a state machine, mouse click if its a strategic game and so forth.

    Path found

    Once the "Find path" have found an calculated a path this event will trigger. The reason I call it a trigger is because you will notice that when you add it, it have a small green arrow to the left of it. All events or almost all event with such arrow are triggers, there are some events which look like they are triggers, but ain't (think its a bug). But as a general rule a green arrow means an event is a trigger. This means they will "activate" once a certain condition occurs, in this case it will trigger once a path have successfully been found.

    Since its a trigger it needs to be placed on the top level or as a starting condition.

    On path found -> <Do something>   (Correct)
    
    On Mouse click
            - On path found -> <Do something> (Not correct)
    [/code:2ag6mw6c]
    
    Typically once a path is found you want to use the action "Move along path" as it will make the unit execute the path it found. So a normal path finding setup would look something like this:
    
    [code:2ag6mw6c]
    1. Unit.Have_orders = False
        For each Unit                      --->  Find path (X,Y)
                                                 Unit.Have_orders = True
    
    2. On Path found                    ---> Move along path
    
    3. On path found fail             ---> Unit.Have_orders = False
    [/code:2ag6mw6c]
    
    [b]3. Path not found[/b]
    This is used so should a unit fail to find a path you can react on it. but it works the same way as On path found. 
    
    [b]Your game[/b]
    After reading the above, I guess you can see why yours are not working correctly. 
    
    1. You have added the find path in an every tick event. So it will try to find a new path 60 times a second. So you will "overload" it with trying to find new paths.
    
    2. The On path found trigger is placed in a sub-level of the every tick event. But since its a trigger it needs to be placed on the top level as a starting condition.
    
    For your map you really should look into using a tilemap instead of sprites. It will increase the performance a lot and will also make it a lot easier for you to work with when designing the map it self. Just add a solid behaviour to it and the units will collide with any painted tile of the tilemap.
    
    Hope that explains it a little and how to fix it.
  • Besides all things nimos pointed out:

    Your player is a solid. Since you have set solids to be obstacles, the player is an obstacle.

    You can not find a path to a position that is inside an obstacle.

    Defining objects (as you do with the walls) as obstacles has no function if you have solids set as obstacle.

    Would you set obstacles to custom and add the walls to the obstacles, then (since they dont move) once (in the on layout startup) is enough. Adding objects to the obstacles must be followed by a 'regenerate obstacle map'.

    I am afraid the grid is to narrow for official pathfinding plugin, afraid it can not find a path that keeps the enemys out the walls.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Here is a way to find solid working paths in tight places & move a player in tight places.

    https://www.dropbox.com/s/m3ypzxx77f436 ... .capx?dl=0

    Need those plugins.

    viewtopic.php?t=68958&start=0

    behavior-moveto_t63156

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