Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 w-harri · Feb 22, 2021 at 08:19 AM · navmeshdrawingmesh colliders

Find and draw shortest route around a mesh collider

Hi,

I couldn't find any code example for the following problem. I really hope someone could help. I want to let player draw a path (the black line in the example image). Then I want to render the shortest possible route (green line). The drawing can start and end anywhere but the route should always start from the players position (blue dot in the image) and go around the grey areas.

My current functions for drawing the line are like below (following a tutorial) but then I released my incompetence :)

alt text

     void ResetLine ()
     {
         lineRenderer.positionCount = 0;
         targetPos = 0;
     }
     void CreateLine()
     {
         fingerPositions.Clear();
         fingerPositions.Add(Camera.main.ScreenToWorldPoint(Input.mousePosition));
         fingerPositions.Add(Camera.main.ScreenToWorldPoint(Input.mousePosition));
         lineRenderer.SetPosition(0, fingerPositions[0]);
         lineRenderer.SetPosition(1, fingerPositions[1]);
     }
     void UpdateLine(Vector2 newFingerPosition)
     {   
         fingerPositions.Add(newFingerPosition);
         lineRenderer.positionCount++;
         lineRenderer.SetPosition(lineRenderer.positionCount - 1, newFingerPosition);
     }


example.png (15.6 kB)
Comment
Add comment · Show 1
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 JasonsFreeTime · Feb 22, 2021 at 03:22 PM 0
Share

Jumping on here just because I was working on a project where we were looking at a similar situation. We never ended up really attempting to solve it but the basic problem was a bit more defined than this question. In our case we were working on an AR application that we wanted to guide a user on a path around a physical object, (such as a large machine) to where the AR content was. So this was a 3D navigation problem, but as the user was floor-bound and we had a good sense of the dimensions of the physical object they would be walking around, it might be really a 2D problem and solvable using a nav mesh. We would need to display some kind of line on the floor (but also probably projected up to about chest height) so that the user could follow it around the machine. And of course we would want them to take the shortest path based on their current position relative to where the 3D overlaid content was.

2 Replies

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

Answer by Llama_w_2Ls · Feb 22, 2021 at 10:21 AM

You could try a pathfinding algorithm. They calculate all possible routes from one point to another that don't cross paths with any walls/obstacles and return the shortest path. You can try the A* pathfinding algorithm, from the asset store, which uses a grid to do this. Or you could implement it yourself, if you're up for the challenge. @w-harri

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 w-harri · Feb 22, 2021 at 07:12 PM 0
Share

Thanks! That seems like a good direction to go.

avatar image
0

Answer by Bunny83 · Feb 22, 2021 at 10:33 AM

Well your problem is very vague. The initial problem seems to be you want to get a player from A to B. What if there's no colliders in the way? so you could fly / walk / move in a straight line. You usually want to do the mesh "hugging" when there's an obstacle in the direct line of sight. So once you reach the bottom most point on the first mesh you get a direct line of sight to the target so what on earth would cause your player to take that detour you drawn? Based on what decision? What if there are 10 other colliders? Does the player have to visit all of them? As I said the initial problem is not clear at all. Also you said the shortest path. However you drawn a hugging path which naturally is longer on any concave mesh.


Finally the most important question: Is this a 2d problem or 3d problem? In 3d it becomes much more difficult and my first questions get even more degrees of freedom. So your exact wanted behaviour has to be narrowed down first. Note that getting pathfinding right is a quite tough topic.

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 w-harri · Feb 22, 2021 at 03:13 PM 0
Share

Thanks for the clarifying questions. I try to make more sense:

  • It's a 2D problem

  • First the player draws a route (with mouse or finger) that they would like to move the blue dot.

  • So the initial input for the final route would be the line that the players draws. The first target is the starting point of that line. If the starting point cannot be reached due an obstacle it should find the shortest possible route to go as close as possible to that point.

  • The route should be calculated after the player has finished drawing the line (=lifts the mouse button or the finger).

  • The final route (green line) can't go through the obstacles (grey areas in the picture).

  • The final target (=where player stops drawing) should be reached with $$anonymous$$imum distance while still following the drawn line as closely as possible (as long as the the line isn't inside the obstacle).

I hope this clarifies. Thanks for the answer!

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

Draw path along Navmesh agent path 3 Answers

Unity 4.5 - NavMesh Obstacle Carving Shape 1 Answer

Uzing Navmesh (free) for climbing AI 0 Answers

How do I apply force for movement when using the NavmeshAgent for navigation? 1 Answer

NavMesh flee. Ai flee from player. 4 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