Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 /
This question was closed Jul 12, 2015 at 03:43 AM by KazeEnji for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by KazeEnji · Jul 11, 2015 at 07:02 PM · unity 5scripting problempathfindingboardgame

[C#] How to make a pathfinding system for a board game?

So I've been trying to get this for a while now and I've revisited the issue a number of times. Take a look at the picture below:

alt text

The white lines are debug lines showing how the waypoints are connected. Each waypoint has an up, down, left, and right GameObject variable in a C# script that I manually assign in the Inspector.

alt text

I've been racking my brain trying to think about how to actually calculate movement through this setup. I had an old version of this that basically sent a pathfinder GameObject through the waypoints based on the movement number the user rolled with a dice. It would duplicate itself when I ran into a waypoint that had multiple connections. This worked properly except there was no way to return the different paths. Since the pathfinder was duplicating itself at every necessary branch, when it reported back to the player about it's current location, it would overwrite the list held by the player.

If I didn't have it report the list back, it still worked but then the problem became that the player was required to move each step individually. I want the player to be able to do that if they choose but I also want the player to be able to just click on an ending waypoint and have the character move through the waypoints to get there.

Has anyone done this before? Thoughts on how I might go about it? I've thought of trying to add everything to a list or multidimensional array but I run into one of two problems. Either the array constantly gets overwritten or the waypoints are added with no particular order so it's useless at that point.

Thanks! -Kaze-

editorlines.png (444.0 kB)
waypointinspector.png (90.6 kB)
Comment
Add comment · Show 2
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 Lahzar · Jul 11, 2015 at 08:35 PM 0
Share

Okay, so here is what I think you should do. This is mostly theory because I dont have time to write code:

Go get the A* Project by Aron Granberg. Free version, doesn't matter. Generate a grid on your map. You might want a manual grid so you have full control of the points! Use tags or something to make everything outside the actual board unwalkable, so you just have single lines of nodes. When the player clicks you find the closest node to where the player clicked. Now you set the final target to the clicked node. Next good thing about the A* project is that you can now get all the nodes in the path from the player to the final target. Now you can do calculations based on the previous information. Each node is a move. You don't need to keep track of entire trees etc. Everything you mentioned is easily acheivable trough this, I think, so if you have any questions you can just ask right here or pm me :)

avatar image KazeEnji Lahzar · Jul 11, 2015 at 11:10 PM 0
Share

Interesting...I'll take a look at the A* stuff. I tried it a while ago and it kept giving me errors so I scraped it and haven't really gone back.

I use the Unity Navigation system now for some of my stuff...any idea of that could work in a similar fashion to what you described with A*?

EDIT: I think I just had an idea...I'll try it and get back to you!

1 Reply

  • Sort: 
avatar image
0

Answer by KazeEnji · Jul 12, 2015 at 03:42 AM

I figured it out! My setup has a lot of if statements in it...going to need to see if I can simplify it. Basically, I've created a pathfinder for my specific type of board that doesn't need any actual pathfinding object, it just throws a variable through the scripts nearly instantaneously. I'm so excited!

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

Follow this Question

Answers Answers and Comments

22 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

Related Questions

Rpc logic with bools, using tutorial scripts, can't find the flaw 1 Answer

Problem moving Rigidbody with UI buttons 2 Answers

Is there a limit on how far a navmesh agent can go? 0 Answers

MoveTowards issue, animating ui. 1 Answer

Changing Custom Object Variable 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