Pathfinding and Dynamically Created Sprites (Walls

Get help using Construct 2

Post » Wed Apr 10, 2013 5:14 am

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!
B
3
G
1
Posts: 6
Reputation: 612

Post » Wed Apr 10, 2013 5:46 am

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.
Project Lead of Zems Online Card Game

Producer at Impulse Limited
B
18
S
6
G
3
Posts: 677
Reputation: 5,194

Post » Wed Apr 10, 2013 4:44 pm

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
B
3
G
1
Posts: 6
Reputation: 612

Post » Wed Apr 10, 2013 4:58 pm

I'm assuming you have the settings to Custom Obstacles? (I'm having what seems to be a similar issue.)
I'm seeking Narnia. Who wants to come with me! Aslan is on the move!
B
113
S
20
G
8
Posts: 741
Reputation: 13,661

Post » Wed Apr 10, 2013 5:39 pm

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.SmallChief2013-04-10 17:44:27
B
3
Posts: 7
Reputation: 289

Post » Wed Apr 10, 2013 7:16 pm

@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.
B
3
G
1
Posts: 6
Reputation: 612

Post » Wed Apr 10, 2013 7:28 pm

Could you upload the file ore an exerpt of it?
B
3
Posts: 7
Reputation: 289

Post » Wed Apr 10, 2013 8:00 pm

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.
B
3
G
1
Posts: 6
Reputation: 612

Post » Wed Apr 10, 2013 8:05 pm

@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.
B
3
G
1
Posts: 6
Reputation: 612

Post » Wed Apr 10, 2013 8:20 pm

@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'm seeking Narnia. Who wants to come with me! Aslan is on the move!
B
113
S
20
G
8
Posts: 741
Reputation: 13,661

Next

Return to How do I....?

Who is online

Users browsing this forum: linkman2004, R0J0hound, SpartCrafter and 27 guests