Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Possible move mesh from NavMesh

Discussion in 'Scripting' started by LeftyRighty, Jan 11, 2016.

  1. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    Point and click game using unity's navmesh to move things around. What I'm struggling with is generating a mesh to be displayed to the user, so that when the unit is selected a "possible move area" mesh can be brought up. I.e. all parts of the navmesh within "2" (or whatever distance) of the agent.

    I've made an illustration from a screenshot and paint; green would be the expected area of the display mesh, red is "in range" but not reachable, yellow would be "in range" if you could go straight to it, but is actually "out of range" because of the shape of the navmesh.



    I've built meshes before for view arcs from raycasts etc., but this is my first time trying to combine that with the navmesh.

    Any thoughts?
     
    Lofar42 likes this.
  2. Lofar42

    Lofar42

    Joined:
    Oct 11, 2014
    Posts:
    12
    Ever get anywhere with this? I'm looking to do something similar
     
  3. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    One idea would be to extract the NavMesh mesh, then use a shader to intersect a spherical shape (just use distance, for example) to decide what is visible or not. You could set alpha channel or use clip intrinsic function (I think it was called that). Then you would have to devise some ways to achieve the colorization for inaccessible areas etc.
     
  4. Lofar42

    Lofar42

    Joined:
    Oct 11, 2014
    Posts:
    12
    Thanks! Yeah this is roughly what I've got going as a solution. My unknown right now being the way to determine if the unit can reach the area (is in range).
    I think when I re-look at this bit of my project I'm just going to "brute force" it and run a series of vertical raycasts in a Horizontal-planed grid that encompasses the max theoretical move distance, sampling each hit for whether it lies within navigation range of the unit, then use that data to construct a new mesh. Will have to balance the resolution of that grid to meet performance requirements etc, but should work in theory.
     
  5. MythrilMan51

    MythrilMan51

    Joined:
    Apr 24, 2017
    Posts:
    146
    I would bet so, I, too, and doing something similar. I hijacked a tutorial and make it that it updates, like... Once.
    Now how to make it intersecting faces can merge, I've yet to scour the internet for that one.
     
  6. Belze006a

    Belze006a

    Joined:
    Apr 2, 2020
    Posts:
    1
    Hi, could anyone of you make any progress in this? Lofar42, what you described as bruteforce also came to my mind. Intersecting a sphere of radius = movementRange with the navmesh and projecting via x Navmesh.SamplePosition calls. For all the positions between I thought of interpolating. However, I did not know that you can pull the mesh directly to create a new. Do you have any code snippets?