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 /
  • Help Room /
avatar image
0
Question by glorious7poo · Jul 25, 2021 at 01:42 PM · navmeshpathfindingprocedural meshastarpath-finding

Obtain multiple paths to target using navmesh

Hi all,
I am new to game development and I am working on a 3D procedural platform level generator.
I autogenerate the navmesh (plus offmeshlinks) with the platform. I am currently using unity navmesh inbuilt CalculatePath to check if there is a path from a start point to the end point. This gives me information on the shortest path available from the start point to the end point. A single path. I also want to be able to determine the number of alternative paths to a given goal.
I have come across arongranberg A* Pathfinding Project (Free version) and it mentions the AlternativePath class .

My question is, I am struggling to see how to use AlternativePath to penalize nodes so that when I call the seeker again, it doesn't choose that same path. Not sure if I understood things properly but it should be able to do this?

I basically want to use the example given in MultiTargetFree.cs but with multipaths instead of multitargets.

I've tried the following but it doesn't seem to work:

 using System.Collections.Generic;
 using System.Linq;
 using Pathfinding;
 using UnityEngine;
 
 public class TryGetAllPaths : MonoBehaviour
 {
     public HashSet<List<Vector3>> allPaths = new HashSet<List<Vector3>>();
     public int counter = 5;
     private Seeker seeker;
     private Path currentPath;
     private bool printList = true;
 
     public List<Vector3> path1 = new List<Vector3>();
     public List<Vector3> path2 = new List<Vector3>();
     public void Awake()
     {
         seeker = GetComponent<Seeker>();
     }
 
     public void Start () {
        seeker.StartPath (transform.position, transform.position+transform.forward*10, OnPathComplete);
     }
 
     public void Update()
     {
         while (counter > 0 && currentPath!= null && currentPath.IsDone())
         {
             currentPath = null;
             seeker.StartPath(transform.position, transform.position+transform.forward*10, OnPathComplete);
             counter--;
         }
 
         if (counter == 0 && allPaths.Count > 2 && printList)
         {
             List<List<Vector3>> tmp = allPaths.ToList();
             path1 = tmp[0];
             path2 = tmp[1];
             printList = false;
         }
         
     }
 
     public void OnPathComplete (Path p) {
         //We got our path back
         if (p.error) {
             // Nooo, a valid path couldn't be found
         } else {
             currentPath = p;
             var altPath = GetComponent<AlternativePath>();
             allPaths.Add(p.vectorPath);
             // Debug.DrawLine(p.vectorPath[0], p.vectorPath[p.vectorPath.Count - 1], Color.green, 10);
             altPath.Apply(p);
         }
     }
 }
 

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

176 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 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

Navmesh path to best of several destinations 0 Answers

A* 2D Pathfinding not working with prefabs? 0 Answers

File Path Confusion for Sharing an Image 0 Answers

Patrol System for instatianted Game Objects,How do I make a patrol system but the instanted objects have their unique patrol 0 Answers

[Unity .3.03f] NavMeshAgent stops after rebaking NavMeshSurface 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