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 /
  • Help Room /
avatar image
0
Question by MONKYfapper · Oct 08, 2015 at 04:19 AM · c#pathfindinggrid based gamestrategyrecursion

Turn base strategy possible move recurrsion bug

the 1st 4 surrounding tiles is perfectly fine. however, when it start looking for the surrounding nodes after. path finding go all over the place

1st column is with recursion and it is bugged, second is without and it works fine (but cannot search anymore tiles)

http://i.imgur.com/6HSRJ8M.jpg

green is all the places you can move to. purple is the clickable tiles you can select (1st 4 surrounding tiles)

objective of the program:

  1. get 4 clickable tile surrounding the unit (up, down, right, left)

  2. find all the possible spot they can move to by recursively searching the surrounding tiles to the 4 clickable tiles

  3. then move to one of the 4 click able tiles and restart from step one until there is no move left

explanation of program:

  • the 1st run will get the 4 surrounding tiles and make them clickable, it then recursively get 3 surrounding (unclickable) tiles from each of the 4 original tile, then it would get 3 more from each until moves = 0. when i click on a tile, it would rerun the entire program to get the next 4 surrounding clickable tile and find farthest possible move the unit can get to.

  • int DirectionFrom tells you where it came from last (1 = up, 2=right,
    3=left, 4=down). if went down last,
    it would not search the node above.

  • the grid is created by a forloop, it will always be perfect square
    starting from 0,0.

//FieldManager

 //the 4 nodes from the last position
 //to see if they should be clickable
 public void PathFinder(int move, int jump, Vector3 pos, int DirectionFrom, bool check){
     //find the nodes -> call a funtion there to check -> 
     findU = ((int)(pos.y)) + 1;
     findD = ((int)(pos.y)) - 1;
     findR = ((int)(pos.x)) + 1;
     findL = ((int)(pos.x)) - 1;
     if ((DirectionFrom != 1) && (findD >= 0)) {
         childname = pos.x+"-"+findD;
         transform.FindChild(childname).GetComponent<TileInfo>().CheckMove(move, jump, pos, 4, check);
     }
     if((DirectionFrom != 2) && (findL >= 0)) {
         childname = findL+"-"+pos.y;
         transform.FindChild(childname).GetComponent<TileInfo>().CheckMove(move, jump, pos, 3, check);
     }
     if((DirectionFrom != 3) && (findR <= FieldX)) {
         childname = findR+"-"+pos.y;
         transform.FindChild(childname).GetComponent<TileInfo>().CheckMove(move, jump, pos, 2, check);
     }
     if((DirectionFrom != 4) && (findU <= FieldY)) {
         childname = pos.x+"-"+findU;
         transform.FindChild(childname).GetComponent<TileInfo>().CheckMove(move, jump, pos, 1, check);
     }
 }

//TileInfo

 public void Set_DC(Color c){
         if (selectable) {
             rend.material.color = Color.magenta;
             default_color = Color.magenta;
         }
         else {
             rend.material.color = c;
             default_color = c;
         }
     }
     public void CheckMove(int move, int jump, Vector3 pos, int DirectionFrom, bool click){
         if (jump >= (((pos.z * (-1)) - transform.position.z))) {
             if (click) { selectable = true; }
             Set_DC(Color.green);
             NewMove = move - 1;
                     //IF I DELETE THE FOLLOWING CONDITION, THE PROGRAM WORKS FINE FOR THE 1ST 4 TILES
             if ((NewMove) > 0){
                 transform.GetComponentInParent<FieldManager>().PathFinder(NewMove, jump, transform.position, DirectionFrom, false);
             }
         }
     }
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

0 Replies

· Add your reply
  • Sort: 

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

31 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

Related Questions

Making square of blocks in match3 C# 1 Answer

Displaying recursive types in inspector (Custom Editor) 0 Answers

Using A* pathfinding plugin, AI doesn't move or move in a wrong direction? 0 Answers

[SOLVED]Unexpected results 0 Answers

Movement following the A* algorithm 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