Simple grid based pathfinding.

0 favourites
  • 14 posts
From the Asset Store
Snap to visible grid - perfect solution for any game genre
  • 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.

  • Have you tried the built-in pathfinding behavior?

    https://www.scirra.com/manual/154/pathfinding

  • Explain what 'the moving' is supposed to do ?

  • 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)

    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...

  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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...

  • 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

  • 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.

  • 99Instances2Go

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

    [...]I gonna try to steer you to use the Official.[...]

    Why? Is the official one faster?

  • 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

  • > 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

    The board is the important part <img src="{SMILIES_PATH}/icon_e_wink.gif" alt=";)" title="Wink">

    I updated your capx example, please find it here.

    https://www.dropbox.com/s/wbm43691jwsaa ... .capx?dl=1

    Regards

    Andy

  • >

    > > 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

    >

    The board is the important part <img src="{SMILIES_PATH}/icon_e_wink.gif" alt=";)" title="Wink">

    I updated your capx example, please find it here.

    https://www.dropbox.com/s/wbm43691jwsaa ... .capx?dl=1

    Regards

    Andy

    I see =D

    Thank you

  • rexrainbow

    I never got the board plugins working. Always crashing on me. Even that example trows me this error ....

    Uncaught TypeError: this.GetBoard(...).xy2NeighborDir is not a function

    at behaviorProto.Instance.behinstProto.target2dir (Rex_GridMove_behavior.js:211)

    at behaviorProto.Instance.Acts.MoveToLXY (Rex_GridMove_behavior.js:701)

    at Action.run_object (eveng.js:1848)

    at EventBlock.run_actions_and_subevents (eveng.js:931)

    at EventBlock.run (eveng.js:888)

    at Runtime.executeSingleTrigger (preview.js:4949)

    at Runtime.triggerOnSheetForTypeName (preview.js:4868)

    at Runtime.triggerOnSheet (preview.js:4800)

    at Runtime.trigger (preview.js:4777)

    at pluginProto.Instance.instanceProto.onMouseDown (Mouse_plugin.js:127)

    at HTMLDocument.<anonymous> (Mouse_plugin.js:66)

    at HTMLDocument.dispatch (jquery-2.1.1.min.js:3)

    at HTMLDocument.r.handle (jquery-2.1.1.min.js:3)

  • 99Instances2Go

    Try update plugins to the last version.

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