Search Unity

WIP My first unity project - navmesh generation

Discussion in 'Made With Unity' started by ChrisPaulson, Apr 11, 2011.

  1. ChrisPaulson

    ChrisPaulson

    Joined:
    Nov 16, 2010
    Posts:
    43
    Hi,

    here is my first c# and Unity project. It's a navmesh generator:-

    http://dl.dropbox.com/u/23080477/navmesh.unitypackage

    This is WIP so there will be lots of bugs and it needs speeding up. I've not yet written a A* on it yet as it is on my to do list but maybe someone could use it and do there own.

    To use it, import the package, make and empty game object and use the component menu to insert the navmesh script. Play with the settings and when ready press scan.

    The collision layer field is not yet implemented so at moment it scans all geom.

    I will continue to work on this as I find time but thought someone might be interested.

    PS

    Be gentle with the comments, these are my first unity scripts.
     
  2. ChrisPaulson

    ChrisPaulson

    Joined:
    Nov 16, 2010
    Posts:
    43
    Here is a demo picture: -


    The coloured squares are the calculated regions.
     
  3. cupsster

    cupsster

    Joined:
    Apr 14, 2009
    Posts:
    363
    subscribed :)
     
  4. AquaGeneral

    AquaGeneral

    Joined:
    Oct 30, 2008
    Posts:
    141
    Very nice work. I just messed around with it and it works pretty well.
     
  5. DavidB

    DavidB

    Joined:
    Dec 13, 2009
    Posts:
    530
    Definitely will check this out, great job from the looks of it. Thanks for sharing.
     
  6. DavidB

    DavidB

    Joined:
    Dec 13, 2009
    Posts:
    530
    Also I forgot to mention, if you wanted to simply test your mesh with A*, my team's started an open-sourced (MIT) navigation framework. It's got a working A* implementation and it's pretty easy to use. I wouldn't say it's production ready yet, but it's definitely robust enough to allow you to test your navmeshes if you can represent them in our NavigationMesh class form. (which is easy to do!)

    http://forum.unity3d.com/threads/67737-Certain-Logic-s-Navigation-Opensource-Framework

    Keep up the great work btw, can't wait to see what you come up with along the way.
     
  7. ChrisPaulson

    ChrisPaulson

    Joined:
    Nov 16, 2010
    Posts:
    43
    Got a little bit further and got Astar working on it: -


    Image shows the regions found by the Astar as the best route. Not yet drawing the path line or doing any path smoothing yet. That's to come next...

    Latest code is in: -

    http://dl.dropbox.com/u/23080477/navmesh.unitypackage

    Still lots of bugs etc but thought I keep the thread updated.
     
  8. Thorgarad

    Thorgarad

    Joined:
    Apr 18, 2011
    Posts:
    10
    Last edited: May 11, 2011
  9. youknownuno

    youknownuno

    Joined:
    Dec 8, 2010
    Posts:
    13
    hello! this seems fun, do you have any built demo? I'm using a mac, but would definetly like to give it a go :)
     
  10. ChrisPaulson

    ChrisPaulson

    Joined:
    Nov 16, 2010
    Posts:
    43

    Thanks - these are bits that show I am new to Unity, I do a clunky bit of code until I can find a better way of doing things. Thanks for the advice.
     
  11. ChrisPaulson

    ChrisPaulson

    Joined:
    Nov 16, 2010
    Posts:
    43
    In the drop box link is the package which you can import and it has an example scene. Press scan when the navmesh object is selected and it should work.

    Do you need more?
     
  12. mgrenier

    mgrenier

    Joined:
    Apr 26, 2011
    Posts:
    57
    Really nice work ! I'm currently building my own navigation mesh + AI and was looking for a way to "scan" my geometry to build the navmesh automatically. Does the resulting mesh can be composed of 1 sub-mesh?

    My own implementation (blog post) uses connected triangles from a single mesh/sub-mesh to build the network (and also merge into convex polygon to reduce network).

    Just wondering :)
     
  13. i3DTutorials

    i3DTutorials

    Joined:
    Aug 26, 2010
    Posts:
    564
    Hi Chris, have you tried your navmesh system with some animated characters/AI yet?
     
  14. ChrisPaulson

    ChrisPaulson

    Joined:
    Nov 16, 2010
    Posts:
    43
    The resulting data is a grid of regions (squares of differing sizes) with connecting links. In the picture above the white squares are the ones found by the Astar. The scanning geometry is done in a similar way to recast. Read this for a good description (this is someone else's work): -
     
  15. ChrisPaulson

    ChrisPaulson

    Joined:
    Nov 16, 2010
    Posts:
    43
    Not yet - it is a near future goal, it's at that point everything will seem worth the hard work.
     
  16. i3DTutorials

    i3DTutorials

    Joined:
    Aug 26, 2010
    Posts:
    564
    Sounds good, congrats on the progress and I hope the best for your end results. I'm sure it will be worth it in the end ;)
     
  17. mgrenier

    mgrenier

    Joined:
    Apr 26, 2011
    Posts:
    57
    Thank you for pointing me to Recast. If you are able to merge your regions into a single mesh (like Recast seems to be doing), I'll easily pay a few hundred for that kind of software !
     
    Last edited: May 13, 2011
  18. ChrisPaulson

    ChrisPaulson

    Joined:
    Nov 16, 2010
    Posts:
    43
    That's what I am doing except I merge into quads not polygons.... and you get it for free!
     
  19. ChrisPaulson

    ChrisPaulson

    Joined:
    Nov 16, 2010
    Posts:
    43
  20. i3DTutorials

    i3DTutorials

    Joined:
    Aug 26, 2010
    Posts:
    564
    Thats really cool. Are you happy with the results or will you be adding more to this, tweaking, etc?
     
  21. ChrisPaulson

    ChrisPaulson

    Joined:
    Nov 16, 2010
    Posts:
    43
    It's just the beginning really, on my to does are:-

    1) Crowd control (local neighbour avoidance)
    2) Path smoothing (either by funnel algorithm or by local A Star)
    3) Dynamic object avoidance (by local A Star)
    4) Runtime updates to navmesh (when something big changes in a scene)
     
  22. i3DTutorials

    i3DTutorials

    Joined:
    Aug 26, 2010
    Posts:
    564
    runtime updating? whoa, you are going all out. Sounds like you're going for the complete package. I would love to see you complete that specific feature, please post a web player demo when you complete it, would be impressive to see. Keep up the good work.