Gamelogic
  • Home
  • Blog
  • Tools
    • Grids 2 (for Unity)
      • Features
      • Documentation
    • Grids 1 (Legacy, for Unity)
      • 30 games in 30 days
      • Features
      • Tutorials, Documentation, and FAQ
      • Games made with Grids for Unity
      • Examples
      • What is new?
      • Grid Prototypes and Previews
      • Buy
    • Extensions
    • Colors
      • Features
      • Documentation and tutorials
      • Buy
    • Words
      • Features
      • Documentation
      • Buy
    • Abstract Strategy
      • Features
      • Documentation and tutorials
      • Examples
      • Buy
    • Match
      • Features
    • Grids (for GameMaker)
      • 30 games in 30 days
      • Features
      • Documentation
      • Buy
  • Buy
  • Articles
  • Support
    • Knowledge Base
    • Email Support
  • About
    • Meet our team

Blog

A simple path-finding example

This example shows how to use the path-finding algorithm that come with Grids on a grid built in the editor (as opposed to a grid built in code).

You can also check out the Path-Finding Tutorial, and a path-finding example with layered grids.

To run the example:

  1. Import Grids in a clean project.
  2. Import one of the packages below into the project.
  3. Open the PathFinding scene, and run it.

Use left-click to toggle whether cells are “walkable”. Right click to alternately place the start and goal. In the Rect example, play around with different neighbor setups to see ho it affects the path.

PathFinding_Hex.unitypackage

PathFinding_Rect.unitypackage

pathfinding_hex

As is often the case when we build examples like this, we discovered two minor flaws in our design.

The first has to do with the CloneStructure method. This method is extremely useful – it allows you to clone a grid in terms of its shape and size, but it can take values of a different type. The idea is to make it easy to make a new grid that is exactly the same as the old grid, except for the contents. It is also used in the CastValues method, which returns a new grid in the same shape as the original, but with the contents casted to a new given type.

Unfortunately, at this moment, CloneStructure (and hence CastValues) does not preserve neighbor relations. So if you set the neighbors of a rect grid to be along diagonals, the clone will not have the same setup – it will still have the default setup. Currently, this affects only rect grids and diamond grids (as they are the only grids whose neighbors can be configured).

The workaround is simply to reconfigure neighbors on the clone.

And trying this workaround while making the example, this is exactly how we discovered the second minor flaw. The GridBuilder does not expose the neighbor setup publicly!

So in  this example, we just run the path finding on the original grid; you can get more details on this in the comments in the code.

We will of course address both these issues in an update!

Share this:

  • Click to share on Facebook (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Reddit (Opens in new window)
  • Click to share on Pinterest (Opens in new window)

Related

  1. A new look at layered grids: setting up neighbors  The layered grid is a very generic type of grid....
  2. How do we make it easier to create simple grids?  Over the last few days we have been investigating making...
  3. Grids 2.1  Grids 2.1 was accepted today. It contains a few minor...
  4. Grids 1.10 is out!  This is mostly a maintenance update, where we made many...
  • Permalink
  • Posted: 25 May 2014
  • Tags: path-finding
  • Author: Gamelogic
Recent Posts
  • Tool Documentation Overhaul
  • What is new in Grids Pro 2.3.5
  • What is new in Grids Pro 2.3.2
  • What is new in Abstract Strategy 2.1.1
  • What is new in Words 2.0.2
Categories
  • 30 Games in 30 Days
  • AbstractStrategy
  • Aside
  • Colors
  • Example
  • Extensions
  • General
  • Grids
  • Grids 2
  • Previews
  • Programming
  • Social Media
  • Uncategorized
  • Words
Follow us on Twitter
My Tweets
Meta
  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org
  • Home
  • Features
  • Blog
  • About
  • 14 Eglin Road, Sunninghill, Johannesburg, South Africa
  • support@gamelogic.co.za
Stay Connected
  • Facebook
  • Google
  • Linkedin
  • Rss
  • Twitter
  • Gamelogic © 2013