Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 coolfireking2 · May 20, 2016 at 07:58 PM · c#pathfindingloopforeachlogic

Logic question, unique path finding system

Hello everyone,

I've been battling with this problem for a while now and haven't come to any conclusions on how to fix it, the details are as follows.

I'm working on a top down map of the UK which has major locations on it, these locations can be connected via links which can be purchased. What I need is a system to find connections from one location to another using the links, then add them to a list.

Here is the information we have to work with;

  • A list of all the links that's currently on the map

  • Access to the 1st location the link is connected to and 2nd location the link is connected to.

I just really need help with the logic surrounding this, it's frying my brain, hehe.

Here is a diagram showing the map and how I need it to work.

alt text

As an example for code, I can add all the nearby locations by simply doing this:

 foreach(Link e in gameObject.GetComponent<LinkManager>().links){
       if(e.Location1Name == LocationName){
              nearbyLinks.Add(e);
       }
 }

Any help is greatly appreciated, I just need someone else's views on this problem.

Thanks!

Joseph

path.jpg (264.3 kB)
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
2
Best Answer

Answer by FortisVenaliter · May 20, 2016 at 08:02 PM

Honestly, as long as you know the distances between them, and have logic for the connections, you can actually use A*. It's designed for grids, but the algorithm is versatile enough to be easily modified for node-based pathing. Wikipedia even has a great article on it with pseudocode.

Comment
Add comment · Show 2 · 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 coolfireking2 · May 20, 2016 at 08:07 PM 0
Share

wow, I never thought of it like that, thanks a bunch!

I'll take a look at the system and get something worked out.

Seriously, thanks again!

avatar image Bunny83 · May 21, 2016 at 02:16 AM 0
Share

It's actually the other way round. A* is generally for node graphs. Though any kind of grid represents a regular node graph. Grids simplifies the concept of neighbor nodes as the grid position already tell which neighbors a certain node has.

avatar image
0

Answer by ninja_gear · May 20, 2016 at 08:24 PM

Personally, I would just use Unity's build in NavMeshAgent.

  1. Attach NavMeshAgent to your UnitObject that moves across the map.

  2. Rotate your map to face up and point the camera down at it.

  3. Set up paths between points to be walkable and bake it.

  4. Set up LocationMarkers on your map

  5. You can then just put UnitObject your map, and set there destination to LocationMarkers on the map and they will walk along the paths.

ProTip: Lock the cameras rotation and use a CharacterController to move it around to 'scroll' the map.

Comment
Add comment · 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

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

6 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Foreach loop doesn't run 2 Answers

Foreach loop inside FileStream 1 Answer

foreach-loop. Is there a gameobject with position existing? 3 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