Pathfinding and Dynamically Created Sprites (Walls

0 favourites
  • 13 posts
From the Asset Store
Units do not overlap each other and use different ways if there are several free ways.
  • I'm seeing the following behavior, which seems odd, and wanted to confirm that others see this too.

    I'm trying to setup a 2d X by Y grid dynamically, and then use pathfinding to move through it. In order to set up the grid, I'm reading JSON from a web server, loading it into a 2D array, and then using that array to layout a series of square sprites ('Wall'), which have a 'solid' behavior, as the walls of my maze. I've gotten the layout working fine, but the problem comes in when I then try to have a different sprite use pathfinding to find it's way through my layout.

    5 seconds after my layout loads (which should be well after the layout is done), I try to use pathfinding on another sprite ('BadGuy') to figure out a path to yet another sprite ('Target'). The Pathfinding Complete event fires, but BadGuy.MoveAlongPath simply results in the BadGuy walking through walls, and heading straight to my target.

    If instead, I simply duplicate my Wall sprite a bunch of times, and hand layout my maze, pathfinding works as expected, and BadGuy weaves down my hallways, and not through the walls.

    This seems to be related to Pathfinding not respecting sprites created dynamically, even if they have the Solid behavior.

    Is this expected? If so, is there a way around this?

    Thanks!

  • Are you updating the path after each wall is created?

    I have asteroids moving around every millisecond in my space shooter, and so I have to update the path quite often.

  • I'm not updating after each wall is created, i'm actually waiting until the whole set of walls is created _before_ i even do the pathfinding (5 seconds after the walls are created, roughly).

    I'll keep debugging and see what I can find.

    -adam

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I'm assuming you have the settings to Custom Obstacles? (I'm having what seems to be a similar issue.)

  • I think what Exal meant, was that you have to udate every "pathfinders" obstacle map when you create a new obstacle.

    Edit: You also have to find a new path after updating the obstacle map.

  • Rhindon - No, I'm using "solids" as my obstacles. I'm looking at Custom Obstacles right now, trying to understand how they work. I built a minimal repro to see if I could post the capx, but it doesn't repro... doh. In that, I create a single wall, and then pathfind to it on mouse click, and it works as expected. That one uses "solids" for Obstacles as well.

    SmallChief - Thanks for the clarification. In my case, I'm definitely doing a new "find path" after the obstacle map is updated. In fact, I've written some debug code to simply path find to the mouse on double click, after the walls are dynamically created, and the behavior still persists - pathfinding ignores the walls, and walks right through them.

  • Could you upload the file ore an exerpt of it?

  • I'm trying to build a minimal repro... since it loads from a webserver that's currently on localhost, that means publishing the .json data files to a web server too... so it might take awhile.

  • Rhindon - changed to custom obstacles, and the problem persists. I'm registering my 'Wall' sprite as an obstacle on start of layout, then adding a bunch of them dynamically, then doing the pathfinding, and it seems to still not work.

    More updates when I have some.

  • stratospheres - Yeah, that's what I'm experiencing, too. My latest effort shows some odd behavior by my enemy object...likes he's constantly trying to find a new path when I'm in range. But it also ignores walls that I've identified as obstacles (including regenerating the obstacle map). I'm wondering if I haven't put the regen map action in the wrong spot...

  • I messaged Wrangler for help (he wrote a tutorial using Pathfinding) and he said he seemed to get my .capx to work by setting the Pathfinding cell size to 0. You might want to tweek your settings, as well... See if that helps.

  • Rhindon - interesting. I set my cell size to 0, but it's still broken. Still digging...

  • Sorry for necromancy, but I think this might help for people who has the same problem. In my case, using Action: Regenerate Obstacle Map after adding new walls fixed it.

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