A* Array Pathfinding

Show us your completed creations made in Construct 2

Post » Sat Jan 26, 2013 4:12 pm



An Example of custom path-finding using arrays:

A* Wizard

Left Click : place selected tile type
Right Click : to place orb
Middle Click: move wizard to mouse
Click Move: make wizard go to the orb

the wizard avoids moving over water, but tries to move over rugs.


for a link to the .capx fully commented but without all the unnecessary stuff click here:

tutorial.capx

For an extended rant of applications click here:

Rant

________________________________________________________________________

was trying to get this up in the arcade for like a week. but it doesn't seem to like me very much.
----------------------------------------------------------------------
Ashley : "Events aren't well suited to highly algorithmic code like the A* algorithm - that's part of what plugins are for, to offload the algorithmic things. So I'd go for the PathFinder behavior."

^This is true, but if you want to do it the long way, arrays are the way to go.^

also since A* is so flexible, the chances of finding a plugin that fits you perfectly are pretty small.
and if you don't know how to code in JavaScript(sense your using C2 chances are you don't). this is your best bet.Bartosh2013-01-26 21:04:22
B
6
S
2
G
5
Posts: 249
Reputation: 2,323

Post » Sat Jan 26, 2013 8:05 pm

[QUOTE=Bartosh]^This is true, but if you want to do it the long way, arrays are the way to go.^

also since A* is so flexible, the chances of finding a plugin that fits you perfectly are pretty small.
and if you don't know how to code in java(sense your using C2 chances are you don't). this is your best bet.[/QUOTE]

Once again Java is not JavaScript and HTML5 is JavaScript based.
Also there are already a few pathfinding plugins and behaviors released in the forum dedicated to third-part plugins.

Nicely working example though, but would it work on any kind/size of layout without a major rework of the algorithm ?
I only took a quick look at the code, but first event in the algorithm being a loop of 0 to 100 seems pretty limiting.Kyatric2013-01-26 20:05:51
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,999
Reputation: 57,793

Post » Sat Jan 26, 2013 9:03 pm

@ Kyatric
"Java is not JavaScript and HTML5 is JavaScript based."

whoops my bad. (FIXED) thanks.

--------
I'm sure those plugins work great, and will get people were they want to go most the time. I haven't looked at them much, so maybe they have a lot more customization than C1's path-finding behavior.

but the main reason I put the time in bringing this tutorial over to construct 2 is because i think its worth peoples time to try and learn this system themselves.

Personally A* was one of those things that seemed impossible for me to grasp. But when i took the time to stop using plugins as a crutch, and dove in. i found a wealth of knowledge , and leveled up as a game-maker majorly.
   it opened up all kinds of possibility's. (thus my crazed rant).

I realized A* doesn't just search tile maps. it can search thru any node system.

which is awesome.
and construct handles A* in the array object surprisingly well.
--------------------------
thus the code itself can't really be plugged in and played as is without some complications. but its mainly intended to be a simple, good, starting point. not a solution.

I've tried it, as is, on large maps(within reason), and it works fine, the real slow down seems to come from drawing so many tiles. which can be fixed with custom tile drawing/destroying.like this

but if you do that. the loop 100 should be a while loop, with some condition to make it stop if it cant get there. but that just complicates things as far as my example.

However, for truly LARGE maps, you'll need to add on to the code, not necessarily completely re-wright it.
basically breaking down the tile-map array into another smaller array (the Meta Array), then A* search a small segment at a time of the tile-map array based off the META Maps A* Path stored in the object. and that regression could go on forever for GALAXY SIZED MAPS!!....if you wanted...

But A* is A*, no matter what, 2d/3d/40d/waypoints/jumpgates/platformers ext.
what is checked, and how the distance formulas are figured out change.
but the basic process doesn't.

having done absurd complex things with C1's arrays, I'm willing to bet there still the best rout to go outside actual plugin coding in C2.
----------------------------------------------------------------
Plus it( in theory) is compatible with the current arcade.
Bartosh2013-01-26 21:50:36
B
6
S
2
G
5
Posts: 249
Reputation: 2,323


Return to Completed Creations

Who is online

Users browsing this forum: No registered users and 5 guests