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

pathfinding - making turning cost (A-star algorithm)

6 posts in this topic

Hi

Im using an A-star algorithm for pathfinding for my units in my rts game. I didnt make the a-star code myself but rather a wrapper around some code i found. I want to add a cost for turning (changing direction between to nodes) so the pather will prefer to make straighter paths instead of zigzagging.

 

Example:
Units can move in 8 directions between the tiles. When moving NNW (direction 1/16th or 1.30 a'clock) it prefers to go up, up-right, up, up-right (turning 1/8th each tile) instead of going all up it needs, turn once, and then go the rest up-right.

 

Best way to solve this?

Thanks

Erik

0

Share this post


Link to post
Share on other sites
The straight-forward way to do this is to consider a node in the graph to mean a position on the map together with a heading. A node is connected only to the nodes corresponding to turning left or right (same position on the map, change the heading) and moving forward (different position on the map, same heading). However, this means multiplying the number of nodes by 8...
2

Share this post


Link to post
Share on other sites

Alvaro has the right of it for true turning costs, though I think he may just want to prevent zigzagging, so you could alter the F cost to make it more expensive to move to a node if it involves moving in a different direction than the last move.  Maybe store the dx/dy for each move, then compare it to the new potential, and roll it into the F cost?

 

(Also, if you haven't done so already, you may be able to fix your problem by just making diagonal moves more expensive that straight moves, check this thread for more info)

Edited by ferrous
0

Share this post


Link to post
Share on other sites

my diagonal cost is quareroot of 2 already. tried to put this to 1.5 to see what happens but it doesnt change the zigzagging. I dont need true turn-cost, just avoid the worst zigzagging. 

 

Ill look into your suggestions! Any good examples of this would be most appreciated!

Thanks
Erik

0

Share this post


Link to post
Share on other sites

Alvaro has the right of it for true turning costs, though I think he may just want to prevent zigzagging, so you could alter the F cost to make it more expensive to move to a node if it involves moving in a different direction than the last move.  Maybe store the dx/dy for each move, then compare it to the new potential, and roll it into the F cost?

No, if nodes represent locations they "forget" the direction of the last move. The cost of leaving the node is the same for every path through it. Only nodes representing position and direction can distinguish turning from straight movement.

 

Example with no obstacles:

a..
41.
752
.63
..b

As the preferred path from a to b, you want 1-2-3 (diagonal, diagonal, straight, straight) or its symmetrical counterpart 4-7-6 (straight, straight, diagonal, diagonal) rather than 4-5-6 (straight, diagonal, straight, diagonal); the status of 1-5-6 (diagonal, straight, straight, diagonal)  and 4-5-3 (straight, diagonal, diagonal, straight)
is unclear. At node 5 you want to prefer 3 as next node if coming from 4, 6 if coming from 1, demonstrating the need to split location-only nodes into location + direction nodes.

 

Unfortunately the cost of all four paths is going to be the identical with any fudging of diagonal step cost away from the correct factor of sqrt(2), because all have two straight steps and two diagonal steps.

Fudging costs can only affect search order, which doesn't seem a very good idea if you like symmetry and consistent behaviour.

0

Share this post


Link to post
Share on other sites

but cannot you use adjacent cost? I mean the cost to move from a node to all 8 around it?

 

I think my a-star works like that. (since it knows that diagonal is more expensive this is a relationship, no single node is "diagonal" in itself, its diagonal in relation to which node is investigating it)

0

Share this post


Link to post
Share on other sites

 

Alvaro has the right of it for true turning costs, though I think he may just want to prevent zigzagging, so you could alter the F cost to make it more expensive to move to a node if it involves moving in a different direction than the last move.  Maybe store the dx/dy for each move, then compare it to the new potential, and roll it into the F cost?

No, if nodes represent locations they "forget" the direction of the last move. The cost of leaving the node is the same for every path through it. Only nodes representing position and direction can distinguish turning from straight movement.

 

 

In my data representation, each potential move keeps a link to the previous move, so it's just a matter of looking at the previous move, look at it's dy/dx compared to the current tile, compare it to the new potential move's dy/dx from the current tile.  It would basically mean that the search would tend to favor tiles "in front" over tiles to the side. 

 

You're right in that it's just altering search order though, so I'm not sure how helpful it would be to implement it that way.

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