Pathfinding: path followed by sprite is far from the generated path.

0 favourites
  • 12 posts
From the Asset Store
Units do not overlap each other and use different ways if there are several free ways.
  • I'm playing with the Pathfinding Behavior. I'm planning on using it for a point & click kind of game.

    Found paths are all valid. The problem is when the sprite "Move along path". It doesn't move exactly on or near the path. It follows an approximated path based on the pathfinder results.

    Problem: The approximation goes over obstacles.

    Question: Is there a way to adjust the path approximation to follow more closely the pathfinder generated path?

    .c3p used: pointNclick.c3p

    Images to illustrate this:

    Legend::

    Red square = obstacle cell

    Green square = unobstructed cell

    Grey rectangle = player

    Small Red point = pivot of the player

    Black line = pathfinder generated path

    Purple line = Path followed by the player

    Thanks you for your help.

    - EDIT: Added an example project -

  • Do you have a project file (like you took the Screenshots from) that we can use to demonstrate back to you information? Saves us having to recreate it again to help you.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Can you cross reference back to this pathfinding tutorial?

    scirra.com/tutorials/9609/pathfinding-route-visualization

    I haven't added a sprite to it at this time, but it might give you some thought.

  • I added the .c3p in the first post.

    I took a look at the tutorial you suggested: I'm basically doing the same thing so it doesn't help me.

    I want my sprite to move more closer to the pathfinder path. It there something I can do?

  • Setting the Cell border to 20 for the Player got very close to the calculated path, as well as it appeared to better navigate the obstacles.

    I'll dig a little more, but thought I'd pass that on.

  • You are right: With a cell border of 20, it doesn't go over obstacles.

    But it still go over obstacle cells. And the sprite's path approximation is still far from the pathfinder generated path. Also, doing this prevents the player to go near obstacles. In this case, it's not the wanted behavior.

    Of course, I'm still trying things on my side.

  • This link shows a good example wackytoaster.at/parachute/pathfindingShowPath.c3p

    If you hit M on this example all walls show the cells around them.

    If you do the same on your example, you are missing a lot of the cells, especially where you 'go through the obstacles'. Might be a good hint!

  • OK, that looks like the answer. If you look at your family 'walls', Rectwall and Circwall (change opacity to 75) you can see where you are checking for pathfinding. Where the blue isn't covered is where pathfinding will go through the image.

    I changed the big firewall at the top to overlap that large blue piece and it stopped crossing it.

    Creating the map this way is a lot of work for you, and probably not the easiest on CPU. Using tile maps might simplify that, or sprites with SOLID behaviours.

  • I've took a look at this file. My .c3p is also heavily based on the example from Construct.

    [...] you are missing a lot of the cells, especially where you 'go through the obstacles [...]

    I don't understand what you mean. On line 1 of my example .c3p, if you enable the action "background: Set Invisible", you'll have a good look oat the obstacle cells (the red ones). Pictures in my first post also show all the cells in the layout.

  • When you press M on your project, you see...

    When you use the other example you see...

    The obstacle maps aren't aligned on yours.

    Changing your circwall looked a bit better.

    Clearer?

  • OK, that looks like the answer. If you look at your family 'walls', Rectwall and Circwall (change opacity to 75) you can see where you are checking for pathfinding. Where the blue isn't covered is where pathfinding will go through the image.

    I already see where I'm checking for pathfinding. I understand how it works. This is not the problem. Please look elsewhere. My problem is simple: Instead of following the path generate by the pathfinder, the sprite follow an approximation of this path. This approximation is not good because it goes through obstacle. To be clear, those obstacles are placeholder sprite with a Solid behavior.

    I changed the big firewall at the top to overlap that large blue piece and it stopped crossing it.

    The blue shape is only a background image with no behavior. It's only there as a background placeholder. All the 'walls' are covering correctly the blue section. Please focus on something else.

    Creating the map this way is a lot of work for you, and probably not the easiest on CPU. Using tile maps might simplify that, or sprites with SOLID behaviours.

    Sprites used as obstacles already have a solid behavior. Look closely.

    I appreciate your help but please focus on the problem I described in my first post: The sprite follow an approximation of the pathfinder path and this approximation goes over obstacles.

  • On line 1 of my example .c3p, if you enable the action "background: Set Invisible", you'll have a good look oat the obstacle cells (the red ones). Pictures in my first post also show all the cells in the layout.

    Please, try this to see all the cells. Read my post completely.

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