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
0
Question by zmatiaki · Nov 19, 2021 at 04:40 PM · nodesrecursion

Find Next Node - recursive algorithm

Hi,

I am trying to make player being able to move on next available point. For Example Below photo. alt text

  • Player Position is the blue one.

  • Red Nodes are corners and player can not move there , but must pass from corners position to reach grey nodes

  • Player can go to next available grey node

  • Each node has a list which contains Neightbor_Corners [RED] and NeightBoor_Targets[Grey]

  • I don't care about distance of each road the only think I need is to now if its reachable from player

I think solution is to run recursive method from start node and save on a list available next nodes, as long as waypoints.

Any idea? I am bit stacked and not so clever to solve this recursive problem :)


Update Ok let me try to explain with a new picture.

Have in mind that every node (grey or red) have 2 different list one for Grey and one for Red Neightboor nodes. Square are positions that player can go.


Player can go to next position only if ;

  • its connected directly with its current position (example 0 ->[1])

  • Its not connected directly but only through red spherer/corners. (example 0->6->7->8>[5])


Player can not reach position if ;

  • It has first to pass from grey node in order to reach target (example 0->6->7->[4] x->[9])

In this example player is on blue spot and available positions are 2,3,5,4,1.


I hope it helps a little bit. Please feel free to ask me a question

alt text


Update Here is the function that finds available positions.Currently, I am trying to find how to save path using below recursive method

 public void FindTargets(List<GameObject> targets, bool firstTry)
     {
         Debug.Log("***************************");
         //firstTry bool in order not to terminate first check on player's position node
         if (!isItCorner && !firstTry)
         {
             targets.Add(gameObject);
             GetComponent<MeshRenderer>().material.color = Color.yellow;
             Debug.Log("exit function");
             return;
         }
         else
         {
             //Bool in order not to check again already checked corners
             if(isItCorner)
             {
                 Havepassed = true;
             }
             Debug.Log("Non - exit function");
             if (CornerLists.Count==0 && TargetLists.Count == 0)
             {
                 Debug.Log("1 function,Does nothing");
                 return;
             }
             else if(CornerLists.Count > 0 && TargetLists.Count == 0)
             {
                 foreach (GameObject corner in CornerLists)
                 {
                     if (!corner.GetComponent<Beacon>().Havepassed)
                     {
                         corner.GetComponent<Beacon>().FindTargets(targets, false);
                     }    
                 }
                 Debug.Log("2 function");
             }
             else if (CornerLists.Count > 0 && TargetLists.Count > 0)
             {
                 foreach (GameObject target in TargetLists)
                 {
                     if (!targets.Contains(target))
                     {
                         targets.Add(target);
                         target.GetComponent<MeshRenderer>().material.color = Color.yellow;
                     }
                 }    
                 foreach (GameObject corner in CornerLists)
                 {
                     if(!corner.GetComponent<Beacon>().Havepassed)
                     {
                         corner.GetComponent<Beacon>().FindTargets(targets, false);
                     }                        
                 }    
                 Debug.Log("3 function");
             }
             else if (CornerLists.Count == 0 && TargetLists.Count > 0)
             {
                 Debug.Log("4 function,Does nothing");
                 foreach (GameObject target in TargetLists)
                 {
                          if (!targets.Contains(target))
                          {
                                       targets.Add(target);
                              target.GetComponent<MeshRenderer>().material.color = Color.yellow;
                          }
                 }
             }
         }
 }






help2.png (40.7 kB)
screenshot-2021-11-19-at-183154.png (91.6 kB)
Comment
Add comment · Show 3
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 logicandchaos · Nov 20, 2021 at 04:05 PM 0
Share

can you explain the rules better?

avatar image zmatiaki logicandchaos · Nov 20, 2021 at 08:39 PM 0
Share

Ok let me try to explain with a new picture.

Have in $$anonymous$$d that every node (grey or red) have 2 different list one for Grey and one for Red Neightboor nodes. Square are positions that player can go.

Player can go to next position only if ;

  • its connected directly with its current position (example 0 ->[1])

  • Its not connected directly but only through red spherer/corners. (example 0->6->7->8>[5])

Player can not reach position if ;

  • It has first to pass from grey node in order to reach target (example 0->6->7->[4] x->[9])

In this example player is on blue spot and available positions are 2,3,5,4,1. I hope it helps a little bit. Please feel free to ask me a question

alt text

avatar image zmatiaki logicandchaos · Nov 21, 2021 at 09:11 AM 0
Share

Updated post with method to find next available. Any idea on how to save the path. I am thinking about having a dictionary with Gameobject Node, List Path. Any idead on how to save that on the above method?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by elkawee · Nov 22, 2021 at 06:10 PM

If i understand your rule set correctly, use a "Depth First Search" algorithm to determine the set of all reachable red nodes.

Set of reachable grey nodes is ( pseudo code ) :

 s = Set( playerNode.greyNeighbors ) 
 
 foreach ( r in reachable_red_nodes ) {
    s = s.Union( r.greyNeighbors ) 
 }
 
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

131 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Huge Lists cause unity to throw bug reporter and crash? 0 Answers

How to increase the Call Stack Size in Unity? 0 Answers

Raycast and alighning to the terrain 1 Answer

A* pathfinding - incorrect nodes calculated 1 Answer

Unity doesn't like generic stacks built through recursion?? 1 Answer


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