Simple grid based pathfinding.

Discussion and feedback on Construct 2

Post » Thu Mar 16, 2017 7:31 pm

Hey there, I've been trying to use some grid based pathfinding plugins, but I was not able to wrap my head around them...

Is there a way to do this within C2 simply? If not, are there any simple to use ones?
I'd need it only to do the moving, no fancy rotations/ corner cutting etc.
ImageImageImageImage
B
28
S
9
G
7
Posts: 229
Reputation: 5,518

Post » Fri Mar 17, 2017 9:29 pm

Have you tried the built-in pathfinding behavior?

https://www.scirra.com/manual/154/pathfinding
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Fri Mar 17, 2017 11:57 pm

Explain what 'the moving' is supposed to do ?
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sat Mar 18, 2017 2:42 am

oosyrag wrote:Have you tried the built-in pathfinding behavior?

I have, but it isn't very grid accurate... (It doesn't stop moving at the right time, meaning it ends being either in front of, or behind the grid square...)
(The settings I used: Cell size = Grid size, Cell border = 0 or -1 (Didn't seem to make a difference), Rotate object and Diagonals both off)

99Instances2Go wrote:Explain what 'the moving' is supposed to do ?

To move a sprite from a square of the grid to the one the player clicks on.
Hope that cleared it up...
ImageImageImageImage
B
28
S
9
G
7
Posts: 229
Reputation: 5,518

Post » Sat Mar 18, 2017 3:02 am

I see. Maybe you can try adding an additional event with Pathfinding - On Arrived to snap to your target.

Another approach I would try if you need clear steps on your grid during the movement is to set up your own custom movement. Use the pathfinding node expressions to pull out the path the behavior found (maybe into an array), and translate the coordinates to snap to your own grid size (by rounding). Then with the custom movement behavior, set the desired step size (to your grid) and move towards each waypoint/node in succession.
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Sat Mar 18, 2017 12:28 pm

oosyrag wrote:I see. Maybe you can try adding an additional event with Pathfinding - On Arrived to snap to your target.

Another approach I would try if you need clear steps on your grid during the movement is to set up your own custom movement. Use the pathfinding node expressions to pull out the path the behavior found (maybe into an array), and translate the coordinates to snap to your own grid size (by rounding). Then with the custom movement behavior, set the desired step size (to your grid) and move towards each waypoint/node in succession.

The first method looks kinda janky since it's moving smooth most of the way and then it snaps into place.

Can you explain how to make the second option a bit more? I don't really know how to use these behaviours...
ImageImageImageImage
B
28
S
9
G
7
Posts: 229
Reputation: 5,518

Post » Sat Mar 18, 2017 1:46 pm

You can do this with @rexrainbow "GridMove" behavior. The code for this is very simple.

Just add the "Board" & "SquareTX" plugin to your project.
Add a new sprite "tile" and give it the behavior "Chess".
Add the "GridMove" behavior to your player.

On start -> Fill board with "tile" //tile is a sprite object for your ground.

On touched object "tile" -> Player move to "tile.Chess.LX, tile.Chess.LY"

All plugins and behaviors can be found here.
http://c2rexplugins.weebly.com/

Regards
Andy
Image Image iTunes: Match3 | Google Play: Match3
B
98
S
33
G
30
Posts: 1,124
Reputation: 27,805

Post » Sat Mar 18, 2017 3:05 pm

but I was not able to wrap my head around them...

Lets compare 2 plugins. The official one and EasyStar.js pathfinding for tilemap, and wrap your mind around it.
The 3th party is here: behavior-easystar-js-pathfinding-for-tilemap_t129056

The official pathfinder is designed to find the shortest path and to move from node to node in a way that it is effective the shortest path. Therefor it needs to also control the movement. That the pathfinder also controls the movement is at the same time a blessing and a burden. The official pathfinder also takes in account the acceleration, the deceleration and the rotation speed. And that makes it a fairly complex thing, behind the scenes.

All 3th party plugins that i know of dont also move the object. They just find paths and provide the nodes. Up to you to move it from node to node in a way that you find is best.

Since you want to move in a 'grid' i choose for 'EasyStar.js pathfinding for tilemap'. That is the right one for this job. From now on i call it 'EasyStar' and the official one 'Official'.

The Official is (as behavior) attached to the object that needs a path.
The EasyStar is (as behavior) attached to a tilemap.

This has consequences.
The Official finds a path from layout coordinates to other layout coordinates.
The EasyStar finds a path from one tile index to another tile index.

So, lets compare them.
In this capx, i use both to find a path, to show the nodes, and to move from node to node.
To move the EasyStar (it does not move things, just finds paths) i used MoveTo from rexrainbow.
behavior-moveto_t63156

So here is the first capx.
https://www.dropbox.com/s/2p4y99ondeq3f ... .capx?dl=0

So that is the basic setup for both plugins. Notice how the Official moves its sprite over the shortest path. Moving over the grid is NOT the shortest path at all. That is very clear when you compare it to the the EasyStar. Hope this basic setup helps you to use the the EasyStar. But. That is not my target with this. I gonna try to steer you to use the Official.

Now, if you look at the nodes from the Official (the green nodes), they lay perfect on the grid. So we have to force it to take a longer path, not the shortest. A path that moves on the grid.

To do that, i use it to find a path, but i use MoveTo to move the sprite over the path.

Done that in a capx.
https://www.dropbox.com/s/vho1dil31phms ... .capx?dl=0

As you see, now it moves perfect over the grid. I do the moving myself because i am not interested in the shortest path movement provided by the Official.

For the purist. Yes, i can do that without a 3th party plugin. (correcting for dt is up to you then)

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

Now you have 2 methods. And both work flawless.
Just choose based on what path you want. Because the EasyStar and the Official do provide a slightly different path.

Hope this helped you some.


PS. I am aware that Dropbox killed a lot of download links. I have no idea how this is gonna be solved. And i dont know if i am allowed to distribute 3th party plugins.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sat Mar 18, 2017 11:45 pm

@99Instances2Go
Thank you very much for the indepth reply and for the .capx!

99Instances2Go wrote:[...]I gonna try to steer you to use the Official.[...]

Why? Is the official one faster?
ImageImageImageImage
B
28
S
9
G
7
Posts: 229
Reputation: 5,518

Post » Sun Mar 19, 2017 12:04 am

AndreasR wrote:You can do this with @rexrainbow "GridMove" behavior. The code for this is very simple.

Just add the "Board" & "SquareTX" plugin to your project.
Add a new sprite "tile" and give it the behavior "Chess".
Add the "GridMove" behavior to your player.

On start -> Fill board with "tile" //tile is a sprite object for your ground.

On touched object "tile" -> Player move to "tile.Chess.LX, tile.Chess.LY"

All plugins and behaviors can be found here.
http://c2rexplugins.weebly.com/

Regards
Andy

Hey Andy, I have done what you said (without the fill board thing), but it doesn't work...
Here's the .capx: https://www.dropbox.com/s/upab2qxj9njp3 ... .capx?dl=0
ImageImageImageImage
B
28
S
9
G
7
Posts: 229
Reputation: 5,518

Next

Return to Construct 2 General

Who is online

Users browsing this forum: tumira and 5 guests