Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Superdsgross · May 27, 2015 at 03:49 PM · c#pathfindingdijkstra

Understanding Dijkstra Application

Hi All, I'm currently working on making a tactical RPG type of game and need to have the possible tiles that a character can move to be highlighted and only allow movement to those tiles. It would also need to move the character to the destination after a button press. I've been scouring unityanswers and every other page I can find to understand how to do this. I've found a ton of different uses of the algorithm and a few for my specific use but I'd really like to understand whats going on with it. I understand a little about Lists and I know all the unity basics so far but I don't understand whats going on with the actual scripts themselves.

Here's a few examples of what I'd like to happen: https://www.youtube.com/watch?v=bGsrnJN7iwU https://www.youtube.com/watch?v=dhvf9KCAsVg

I've found some sample code thats pathfinding (not quite the same thing) with Dijkstra: https://letmetutoryou.wordpress.com/2009/05/26/shortest-path-with-dijkstra-and-c/ http://pastebin.com/vf32J1nk

If anybody can either help me understand how this is supposed to work or can find a step by step explanation of how this works I'd really appreciate it.

Thanks

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Multifred · May 27, 2015 at 04:46 PM

There is some animations here.

Dijkstra is an algorithm for any graph, it's not just video game pathfinding. You'll need to understand a little what is graph theory.

To apply Dijskra: you need to set all nodes (a tile here) and all edges (the path between nodes in our case) and to have for each edges a cost (the distance for example or the "difficulty") and 2 nodes. These nodes are neighbours.

When you are looking for a path, you actually check all neighbour of your current position, discard "too expensive" path move your current position to the next position and repeat until you reach your destination.

All the difficulty of Dijskra's algorithm is to understand how to discard too expensive path.

Another article from AI Game Dev

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Superdsgross · May 27, 2015 at 05:01 PM 0
Share

Thanks, I'll look into graph theory a little more. Obviously I already have tiles created and I've been able to put those into a List. Do I need to create a separate object for the edges? Or how would I define those?

avatar image Owen-Reynolds · May 27, 2015 at 05:16 PM 0
Share

?? There's no discarding. All Dijkstra's does is add the "cheapest" edge, over and over.

avatar image Multifred · May 27, 2015 at 11:24 PM 0
Share

@Superdsgross that not necessary all you need (in your case at least) is to know next tile and the distance to it, that couple neighbour/distance is an "edge".

@Owen-Reynolds I'm not a native english speaker so I might not have choose corectly my words but with Dijskra if you find A->B cost 100 and A->A1->A2->...->An->B cost 10 you discard the former path, don't you?

avatar image Superdsgross · May 27, 2015 at 11:47 PM 0
Share

@$$anonymous$$ultifred How can I find adjacent tiles from a list of tiles?

avatar image Multifred · May 28, 2015 at 12:25 AM 0
Share

That depend of your problem: on a chess board the coordinate would be enough to find that quickly.

You should check out some pathfinding tool video, most of them compute the neighbour data and serialize it, that's not something you want to calculate during runtime.

Here an interesting discussion about dynamic pathfinding

avatar image
1

Answer by virgiliu · May 27, 2015 at 04:06 PM

Here are some in depth explanations about some path finding algorithms, including Dijkstra and A*

http://theory.stanford.edu/~amitp/GameProgramming/

These might be of help as well

http://aigamedev.com/open/tutorials/clearance-based-pathfinding/

http://www.ai-blog.net/archives/000152.html

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Superdsgross · May 27, 2015 at 04:27 PM 0
Share

Thanks for the quick reply. I guess my question may be a little vague. I understand the concept and how it should work. I don't understand its implementation. I've seen a few different examples of code and I'd like to be able to get to that same conclusion in my own application.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

Specific 2D movement using Dijkstras Algorithm... 1 Answer

Indexing tiles for pathfinding 1 Answer

Multiple Cars not working 1 Answer

need some help with basic pathfinding with obstacle avoidance 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges