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
0
Question by dev_timecode · Nov 16, 2019 at 08:40 AM · pathfindingwaypoints

PathFinding with fixed waypoints problem

I got this idea to develop but I cant get my head around this (beginner really). What you can see on the image is a map with locations (big circles) and bunch of connections with "stops". alt text What I would like is when i drag my player from one location to another, to calculate a shortest 'route' and then, every turn (game is turn based) advance one stop toward final destination. What i have for now is for each of the locations (the big circle one), i have a class :

 [System.Serializable]
     public class Connection
     {
         public Location NeighborLoc;
         public int Distance;
     }
     public Connection[] connections;

Where for each of the locations i have a list of "neighbor" locations with fixed distance to them (int) - basically a number of small white circles ("stops"). Then i have a function :

 public void CalculateRoute(Location from, Location where)

But, whatever i do in this f-ion I end up in a infinite loop, crash unity or, just never calculate a route :). I tried basically going trough all connections for a location, then for each of those connections, find an endpoint and recursively call CalculateRoute on that location and 'where' locations, this usually ends up as an infinite loop, and, even then, I'm not sure how to go from there (how to find a shortest route, and 'store' this route for later advancing every turn, how to avoid turning back to start location). I'm guessing I should take a totally different approach here (some kind of pathfinding or something?? )

Thanks for any help :)

pb.jpg (302.4 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

1 Reply

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

Answer by toddisarockstar · Nov 17, 2019 at 06:42 AM

for this situation i wouldnt use a grid style of pathfinding. you could acheive your movement starting with a list or array of all your points.

the main array would include nested lists or arrays of all the connections to the other indexes in the main array.

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class points : MonoBehaviour {
     //drag and drop location markers here for reference
     public GameObject [] spots = new GameObject[50];
 
     // inside this array put all the connections to the index numbers of other points
     public int [][] connect=new int[50][];
     void Start () {
         connect [0] = new int[]{2,3};
         connect [1] = new int[]{3,4,5};
         connect [2] = new int[]{6,7};
         // continue this process for all points
     
     }
 
 }

the two dimentional array would give you data you need to acheive the movement for pathfinding.

you would do a flood-fill style algo till you find your end point marking the counted steps on each point along the way.

this way after you find your finish you could trace backwords looking for consecutive numbers down to output your path.

this process is similar to A-star but actually a bit simpler.

if you are still looking to code this yourself let me know and i could help at some point this weekend.

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 dev_timecode · Nov 18, 2019 at 08:23 AM 0
Share

I like this idea, what i did actually was allot more 'dumb' but it works :) : I kept my "connection" class but did it like this:

 [System.Serializable]
         public class Connection
         {
             public Location goal;
             public Location direction;
             public int Distance;
         }
 public Connection[] conns;


Then i'll manually, in editor, fill these for each of the locations (ill add all other locations, and a direction for each of them (basically a first step towards the goal, i calculate this manually, just by looking at the map and counting the steps ). Then it's just looking trough all connections in conns, finding the one with the goal, and appropriate direction, go to direction 'node' - repeat the process.

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

120 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

Related Questions

What is the best AI system for pathfinding on a moving platform 2 Answers

Waypoint tree structure 2 Answers

Move object along the path,Move an object along the fixed path 1 Answer

Why isn't a Ai Waypoint Spawning??? 0 Answers

Waypoints and AI pathfinding 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