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

Pathing Algorithm Help

11 posts in this topic

I'm developing a game that requires some advanced(?) path detection. It is a 2D, top down, turn based game and when the user activates a character, all eligible move positions should be highlighted. So, if they activate their character and no obstacles are around, it should display a circle. If there is an object at the edge of the circle, it should look like the middle picture.

However, if there is an object in the middle, pathing should sort of "blob" around that object. The character can always move 'x' distance, but that distance does not have to be in a straight line, so they can move to the corner of the object then use their remaining distance to move around it, which is why it should show a blobbing effect.

Anyway, if that wasn't clear enough, this is what the effect should look like: (yes, I drew this in paint lol)

[img]http://i220.photobucket.com/albums/dd230/slapshot6819/Pathing.png[/img]
Red: Character
Green: Movement Area
Black: Obstacle
Left shows the obstacle completely out of the way, middle shows the obstacle partially in the way, and right shows the obstacle completely in the way with the "blob" effect.


Assuming I have a 2D array of pixel perfect collision information, how would I generate this effect? Or maybe I should abandon this method and go about it some completely different way?
0

Share this post


Link to post
Share on other sites
You could use something similar to Dijkstra's algorithm. Except instead of looking for a goal, you're just marking pixels as valid move points as long as the movement cost hasn't become too high. Once there are no more pixels left with a low-enough movement cost, you can stop the pathfinding, and all valid pixels should've been found.
0

Share this post


Link to post
Share on other sites
[quote name='Cornstalks' timestamp='1328030007' post='4908073']
You could use something similar to Dijkstra's algorithm. Except instead of looking for a goal, you're just marking pixels as valid move points as long as the movement cost hasn't become too high. Once there are no more pixels left with a low-enough movement cost, you can stop the pathfinding, and all valid pixels should've been found.
[/quote]

Do you think Dijkstra's could work at a reasonable speed? The game is designed for the iPad and whatever method I use for this needs to be fairly efficient.

Edit: I've also heard A* might potentially be useful for this, but just wanted some other opinions.
0

Share this post


Link to post
Share on other sites
[quote name='slapshot6819' timestamp='1328041680' post='4908143']
[quote name='Cornstalks' timestamp='1328030007' post='4908073']
You could use something similar to Dijkstra's algorithm. Except instead of looking for a goal, you're just marking pixels as valid move points as long as the movement cost hasn't become too high. Once there are no more pixels left with a low-enough movement cost, you can stop the pathfinding, and all valid pixels should've been found.
[/quote]

Do you think Dijkstra's could work at a reasonable speed? The game is designed for the iPad and whatever method I use for this needs to be fairly efficient.
[/quote]
Dijkstra's algorithm should be fast enough. You aren't searching the whole map (you're only searching a small circular area within the map). It may, however, require some clever optimizations (not low-level optimizations; I mean high-level optimizations). I don't know how much processing your game already does, so I can't say for sure.


[quote name='slapshot6819' timestamp='1328041680' post='4908143']
Edit: I've also heard A* might potentially be useful for this, but just wanted some other opinions.
[/quote]
A* is very similar to Dijkstra's algorithm, except A* introduces a heuristic to help it guess which nodes to search and which ones to ignore. There are two problems with A* in this case: 1) I can't imagine how you'd come up with a heuristic, because the heuristic depends on you having a specific destination (whereas you don't have any specific destination), and 2) A* just tries to weed out unnecessary checks with the heuristic, but you aren't trying to weed any out (and if it did weed any out you'd end up with gaps in your movable region)
1

Share this post


Link to post
Share on other sites
[quote name='Cornstalks' timestamp='1328043582' post='4908157']
A* is very similar to Dijkstra's algorithm, except A* introduces a heuristic to help it guess which nodes to search and which ones to ignore. There are two problems with A* in this case: 1) I can't imagine how you'd come up with a heuristic, because the heuristic depends on you having a specific destination (whereas you don't have any specific destination), and 2) A* just tries to weed out unnecessary checks with the heuristic, but you aren't trying to weed any out (and if it did weed any out you'd end up with gaps in your movable region)
[/quote]

Hmm okay, this makes sense. Alright, maybe I'll go with Dijkstra's and see where that gets me. Thanks for the help!
0

Share this post


Link to post
Share on other sites
I am unable to see the pictures, but here is the solution i used for my game, it`s something in between the A* and Dijkstra's. I might still work on it a bit more, but so far it works like a charm.

In my case:
each character has a max travel cost
each map point is aware of it`s neighbors and cost of travel between it and it`s neighbor
i already have A* implemented to find a path, used mainly by NPCs.
Each map point stores the point that was used to access it.

When a move command is selected for a player, i get all neighbors from point, and check to insure that the move cost from current point, to next point
does not exceed characters max travel cost.
I more or less repeat the process untill I have checked all available points.

Now when a player clicks one of the available map points, I already have the best path to that point stored in memory that can be used to get the character to the desired point.

Sorry if my explenation is not clear, but i hope it helps.
0

Share this post


Link to post
Share on other sites
What you want is to try and see if the player can move to each pixel in a radius around his current location (ie, each pixel on the outside of your green circle) within a certain number of "steps" (steps being the radius length in pixels, for example). Depending on the size of the circle, if you run Dijkstra's, with the end vertex's being each pixel, it could become costly. But, if your circle is small, then maybe it will be OK.

I wonder, if you did use A*, and set the goal to be each pixel, it could work around the obstacle fine, and then you could use the resulting path, only up to X amount of steps. I don't know how much that would cost either, but it's something to consider.

Or, you could just set the goal to be every 5 Degrees around the circle, that would probably be a good approximation, so you don't check every pixel. I'm just brain-storming here, I've never done this before.
0

Share this post


Link to post
Share on other sites
[quote name='BeerNutts' timestamp='1328126682' post='4908445']
What you want is to try and see if the player can move to each pixel in a radius around his current location (ie, each pixel on the outside of your green circle) within a certain number of "steps" (steps being the radius length in pixels, for example). Depending on the size of the circle, if you run Dijkstra's, with the end vertex's being each pixel, it could become costly. But, if your circle is small, then maybe it will be OK.

I wonder, if you did use A*, and set the goal to be each pixel, it could work around the obstacle fine, and then you could use the resulting path, only up to X amount of steps. I don't know how much that would cost either, but it's something to consider.

Or, you could just set the goal to be every 5 Degrees around the circle, that would probably be a good approximation, so you don't check every pixel. I'm just brain-storming here, I've never done this before.
[/quote]

That's too costly. Running Dijkstra's algorithm as I mentioned would be more efficient (running until a certain move-cost had been reached, rather than a specific end goal). Searching hundreds of times for the perimeter of a circle is expensive.
0

Share this post


Link to post
Share on other sites
[quote name='Cornstalks' timestamp='1328127784' post='4908453']
[quote name='BeerNutts' timestamp='1328126682' post='4908445']
What you want is to try and see if the player can move to each pixel in a radius around his current location (ie, each pixel on the outside of your green circle) within a certain number of "steps" (steps being the radius length in pixels, for example). Depending on the size of the circle, if you run Dijkstra's, with the end vertex's being each pixel, it could become costly. But, if your circle is small, then maybe it will be OK.

I wonder, if you did use A*, and set the goal to be each pixel, it could work around the obstacle fine, and then you could use the resulting path, only up to X amount of steps. I don't know how much that would cost either, but it's something to consider.

Or, you could just set the goal to be every 5 Degrees around the circle, that would probably be a good approximation, so you don't check every pixel. I'm just brain-storming here, I've never done this before.
[/quote]

That's too costly. Running Dijkstra's algorithm as I mentioned would be more efficient (running until a certain move-cost had been reached, rather than a specific end goal). Searching hundreds of times for the perimeter of a circle is expensive.
[/quote]

I don't understand how you would run Dijkstra's without having every pixel on the outer edge being a possible vertex destination. Admittedly, I've only ever used A*, but my understanding of Dijkstra is it still has multiple vertex nodes and can find shortest path to all of them. How do you do use dijkstra's without these nodes?
0

Share this post


Link to post
Share on other sites
[quote name='BeerNutts' timestamp='1328129583' post='4908471']
[quote name='Cornstalks' timestamp='1328127784' post='4908453']
[quote name='BeerNutts' timestamp='1328126682' post='4908445']
What you want is to try and see if the player can move to each pixel in a radius around his current location (ie, each pixel on the outside of your green circle) within a certain number of "steps" (steps being the radius length in pixels, for example). Depending on the size of the circle, if you run Dijkstra's, with the end vertex's being each pixel, it could become costly. But, if your circle is small, then maybe it will be OK.

I wonder, if you did use A*, and set the goal to be each pixel, it could work around the obstacle fine, and then you could use the resulting path, only up to X amount of steps. I don't know how much that would cost either, but it's something to consider.

Or, you could just set the goal to be every 5 Degrees around the circle, that would probably be a good approximation, so you don't check every pixel. I'm just brain-storming here, I've never done this before.
[/quote]

That's too costly. Running Dijkstra's algorithm as I mentioned would be more efficient (running until a certain move-cost had been reached, rather than a specific end goal). Searching hundreds of times for the perimeter of a circle is expensive.
[/quote]

I don't understand how you would run Dijkstra's without having every pixel on the outer edge being a possible vertex destination. Admittedly, I've only ever used A*, but my understanding of Dijkstra is it still has multiple vertex nodes and can find shortest path to all of them. How do you do use dijkstra's without these nodes?
[/quote]

Dijkstra's algorithm just floods out from a starting point until it reaches the end destination. At least that's how it's normally done. You just keep flooding out until you reach the end (and once you reach the end you stop the algorithm, as you've found the shortest path). However, you can slightly modify the algorithm so that instead of stopping the search when a particular point is reached, you can stop the search once all the nodes left to search exceed the maximum movement cost. You don't need to really need to have an "end node" when you run it like this.

The only reason you have a destination node in Dijkstra's algorithm is so you know when you've found the goal and you should stop. You don't need a destination node to run the movement-cost calculation part of the algorithm (unlike A*, which needs the destination node for its heuristic).
0

Share this post


Link to post
Share on other sites
If i remember corectly with Dijkstra's, you let it search all all possible nodes untill it find the node you are looking for, all A* does is adds an estimation to that cost to direct the search in 1 direction.

When running a Dijkstra's algorithm, you expend all nods equaly untill you find desired destination, so as long as you emmit the destination and let it search all nodes with a cost value less then max, it will work without any problems
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