• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
CaiusEugene

A* pathfinding on a sphere projected cube (uneven planetary body)

9 posts in this topic

Hello all, I'm new to the forum so I thought I'd just introduce myself within my first post, so hey!

 

I'm having some trouble wrapping my head around the best approach to generate the data for an A* pathfinding algorithm on my sphere project cube. I've posted my query on a few Q&A websites which has generated a lot of discussion but not many answers, and has lead me to think this is a problem that needs to be discussed on a forum!

 

http://gamedev.stackexchange.com/questions/53866/pathfinding-on-a-uneven-planetary-surface

 

http://stackoverflow.com/questions/16089074/a-pathfinding-over-multiple-grids

 

Background:

 

I've created a small planetary body from 6 planes forming a cube which have been sphere projected forming a sphere each face of my "sphere" has been procedurally displacement mapped to make uneven terrain. Illustrated below.

 

hFgRJ.png

 

I want to be able to implement pathfinding so my agents can traverse the surface of the planet but I'm struggling to understand the best approach to generating the path finding data. 

 

Obviously each face is a mesh of vertices with positions, I can easily take the positions of each vertex from each "sphere face" and generate one big list of nodes, but the problem comes when I'm trying to establish the adjacent nodes. I've considered that I could just precompute all 6 adjacent node for each and every node by doing a brute force distance check, but this just seems so inefficient. Or am I missing an obvious and simple solution?

 

To help better articulate my question this is my current planetary body:

 

4bgPY.png

 

Thanks, Caius.

Edited by Caiuseugene
0

Share this post


Link to post
Share on other sites

I'd put a node at the centre of each quad face on the cube, and use the original cube to get adjacency information (either 4 or 8 nodes depending on whether you want the diagonals connected). The only hassle is at the edges of the cube, not too difficult to cope with that though (and the corners have just 7 neighbours as well).

0

Share this post


Link to post
Share on other sites

use the original cube to get adjacency information (either 4 or 8 nodes depending on whether you want the diagonals connected)

 

Yes that does make sense, will have to sphere project the node data too in this case.

 

The only hassle is at the edges of the cube, not too difficult to cope with that though (and the corners have just 7 neighbours as well)

 

I think the issue is that each face of the cube is actually just a plane, so only contains vertex data about that face. I guess I could supply each face with there X+ X- Y+ Y- faces.

0

Share this post


Link to post
Share on other sites

Well you need to separate your sphere mesh representation from the node representation anyway. As long as you know which face is across from the cube edges it is pretty easy to build the adjacent node list. Using just 4 neighbouring nodes eliminates the 7 neighbour problem at the corners too.

0

Share this post


Link to post
Share on other sites

Well you need to separate your sphere mesh representation from the node representation anyway. As long as you know which face is across from the cube edges it is pretty easy to build the adjacent node list. Using just 4 neighbouring nodes eliminates the 7 neighbour problem at the corners too.


yes I understand now, it's going to be a pain getting the nodes from each adjacent face as rotation of the face as well as its adjacency to the "active face" will have to be calculated in order to return the correct edge. Would using just 4 neighbouring nodes make the algorithm much slower? Edited by Caiuse
0

Share this post


Link to post
Share on other sites

It looks like you will have to store your shortest path node list in memory somehow.
 
Also it seems that you need a bit more than brute force nearest nodes, you may need to exclude mountains and lakes, or assign appropriate values for hard-to-pass terrain.
 
So you may need to take that data you use for the terrain (i will call it "6 sphere face"), and use it to compute "shortest path node" only once (or only when it changes). This can be done and tested separately, until you get it right (even with smaller cube density if needed for testing purposes). In case of the corners, just allow null references for your nodes (if you need diagonal path too).


Every "shortest path node" may have a reference back to original "6 sphere face" node, so you get the real thing if needed.
 
This way your lookup algorithm remains simple and fast yet you do not loose any information about your world.

 

EDIT: As for adjacency of the faces, the most basic approach is naming things right. For example, of two futhermost corners of the box have respectively values of (-1, -1, -1) and (1, 1, 1), this information can be retained in cube face array. For example, cube face array may contain faces from (-1, -1, -1) to (-1, -1, 1) for U and from (-1, -1, -1) to (1, -1, -1) for V. A bit more math, but solving it would help to avoid a lot of repetition. 

Edited by Nercury
0

Share this post


Link to post
Share on other sites

Well you need to separate your sphere mesh representation from the node representation anyway. As long as you know which face is across from the cube edges it is pretty easy to build the adjacent node list. Using just 4 neighbouring nodes eliminates the 7 neighbour problem at the corners too.


yes I understand now, it's going to be a pain getting the nodes from each adjacent face as rotation of the face as well as its adjacency to the "active face" will have to be calculated in order to return the correct edge. Would using just 4 neighbouring nodes make the algorithm much slower?

 

The less neighbouring nodes the faster the algorithm will run but the path won't be as optimal.

 

You only need to calculate the node connectivity information once. Try doing it with a 3x3 node layout per cube face first, it should scale up easily after that. You can always draw the network to check you have worked it out correctly.

 

Don't worry about impassable terrain or terrain with high movement cost at first, just get the network setup correctly. It's easy to add a prohibitively high cost for moving from one node to another if it is blocked later on.

 

You can optimise lookups once you have the network by having a 2d array of precalculated "next nodes" to travel to (will use a lot of memory if the number of nodes is high though). Say you want to go to node D from node A, and the optimal route is ABCD. Store B in the table for entry (A, D) i.e. the next node to travel to from A. The next node for travelling from B to D would then be C, so store that in the (B, D) entry. (You'd store C in the (D, A) entry assuming optimal route from D to A is DCBA).

Edited by Paradigm Shifter
0

Share this post


Link to post
Share on other sites

I would approach this problem the following way:

 

Build a graph G = (V, E) from your mesh, where the nodes V are the movable tiles (ie. faces) of your mesh

and the edges connect adjacent nodes.

Common representations for graphs are adjacency lists and adjacency matrices.

In this case you could even use adjacency arrays, since for each node the number of adjacent nodes is constant.

Each node should have a reference to the face it represents or at least a position coordinate.

 

Finding a shortest path on graphs is a solved problem. Use your favorite algorithm for this, maybe A* or the

general dijkstra. Dont store shortest paths, recompute them. I doubt it will be a bottleneck.

 

Sidenote: as mentioned above, dont introduce special cases with null-pointers to handle impassable tiles.

Just use high costs. Speaking of costs: dont forget to test different measurements of distance.

normal l2-norm might not be the best on a spherical surface.

Edited by plainoldcj
0

Share this post


Link to post
Share on other sites

dont introduce special cases with null-pointers to handle impassable tiles

 

When I mentioned null pointers I was thinking about those corner tiles which have 7 neighbors instead of 8.

0

Share this post


Link to post
Share on other sites

You could construct a linked list to represent the planet's mesh.

 

 

enum Direction{
	Above,
	Below,
	Left,
	Right
};

struct Vertex{
	float phi;
	float theta;
	float r; 
	float cost;
	
	Vertex *neighbors;
};

 

Using this method, the only real effort required is in the initial assembly of the linked list. For pathfinding you would just iterate through the linked list like you would for a normal array.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0