Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Movable Platforms With NavMesh ?

Discussion in 'Navigation' started by DoublePixelStudios, Nov 28, 2017.

  1. DoublePixelStudios

    DoublePixelStudios

    Joined:
    Feb 27, 2014
    Posts:
    97
    Is there a way to be able to move a platform, like a elevator, while using navmesh? I cant seem to find any source that says i can..
     
  2. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    790
    If i remember correctly there are some guides that specifically say that it's not possible using the navmesh.

    But you can do it yourself.
    Assuming your platforms aren't too complex (not whole buildings flying around, but just simple shapes like a circle or a rectangle) then you can simply hard-code the locations where an NPC goes onto a platform etc...

    That's what I'm doing and it works well enough since I realized I don't actually need my NPCs to path-find their way around while on the platform. So not having a mesh there is fine.

    Just take care that the geometry is simple (basically that means no obstacles on the platform object that where a navmesh would be needed).
     
  3. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,846
    Assuming the platform has geometry requiring navigation (why else would anyone use navmesh on it?) then it should work to have an invisible copy far away that doesn't move. You simulate what you need on that, and copy the results to the moving platform actors + suitable offset.

    For a boat or something.
     
  4. TheMonkeysaur

    TheMonkeysaur

    Joined:
    May 2, 2017
    Posts:
    46
    I have come just across this too. I know you can dynamically create obsacles and have them carve out areas of the navmesh, is it really not possible to add to the navmesh with new platforms/areas when they connect to an existing navmesh?

    For example I have a bridge which tweens into position when triggered, but it looks as though I can't add this to the navmesh.

    Any tips or ideas would be appreciated.
     
  5. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,846
    If my above advice was too technical for you to implement, you should probably switch to a waypoint system / simpler navigation for the bridge then.

    Or you can wait for when (if) Unity want to tackle it.
     
  6. TheMonkeysaur

    TheMonkeysaur

    Joined:
    May 2, 2017
    Posts:
    46
    Thanks, do you know if it is something Unity are planning to add? My issue isn't so much that navigation on the the platform is required, it's more that I am using navmesh and navmesh agents to limit the players movement to the platform so they can't walk off it, I prefer this to invisible walls because my player tends to "bounce" off the walls I create, whereas with a navmesh the walkable area is more cleanly restricted.

    Yes my technically abilities are quite limited! I was trying raycast down to restrict movement area to the surface of my platforms but was finding that a bit challenging, I might try that again.

    Thanks.
     
  7. DoublePixelStudios

    DoublePixelStudios

    Joined:
    Feb 27, 2014
    Posts:
    97
    So basically if i have a square.. and i have a character following the navmesh to a point that i clicked on, being the square, there is no possibility of coding this square to move upwards towards a platform so that my character can then access another platform, like a second story? I get that once the navmesh is baked than it is baked into position, i just didnt know if there was a possibility to unbake it in runtime using a script to allow the platform with navmesh on it to move in any direction from script...
     
  8. DoublePixelStudios

    DoublePixelStudios

    Joined:
    Feb 27, 2014
    Posts:
    97
    I finally understand what you are saying.. but my game is like a tower game where you have to solve a puzzle to go to the next tower. i have my guy following a path through out the walkways so that you dont fall off.. i wanted straight paths and not just randomly running around on the platforms. so i used navmesh to guide the character around the scene in straight paths.. since my scene consited of basically 1x1x1 blocks that the character walked on it made the navmesh path narrow which in return made the character walk farely straight and in a clean walk fashion. but the whole object if the game where the puzzles come into play, is that after colliding with a button on the ground a platform is triggered and a elevator, or moving platform if you will, comes down and gives access to another platform that was previous cut off cause the elevator wasnt on the first floor.. get where im going..
     
  9. GameDevCouple_I

    GameDevCouple_I

    Joined:
    Oct 5, 2013
    Posts:
    2,158
    Sorry to necro hippo but yours was the best answer on this topic. I was wondering how you would implement this now that we have c# jobs and ecs, whether there is anything different you would do?
     
  10. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,846
    ECS is still WIP so I honestly would not know the most optimal way without testing, sorry :(
     
    GameDevCouple_I likes this.
  11. christougher

    christougher

    Joined:
    Mar 6, 2015
    Posts:
    419
    I was totally able to get navigation working on a moving surface with the navmeshsurface....

    https://forum.unity.com/threads/dyn...sh-surface-navmesh-agent.467914/#post-3047872

    It's not supported and would likely be terrible performance-wise if you updated a bunch of surfaces with lots of agents but for one agent and one platform I think you could totally do it.

    Some things I believe I did to make this work are to have the agent a child of the moving object , have the agent moving towards a transform of another gameobject that is also a child of the moving platform. If you have it set to move towards a vector3 in world space it will start to path wonky as the platform leaves that vector3 behind
     
    Last edited: May 5, 2018
  12. christougher

    christougher

    Joined:
    Mar 6, 2015
    Posts:
    419


    Here's a modified example scene from the 2018.1 version of the NavMeshComponents on github.

    https://www.dropbox.com/s/kbj5y0rlcxz447t/MovingPlatforms.zip?dl=0

    It includes two new scripts as well. It has an agent following an object that you can click to move between 4 different planes (two are stationary and two are moving). Of note is how I child the agent and target to whatever surface he lands on so as to be grounded to the current walking surface... Hope it is useful for someone...
     
    janla likes this.
  13. GameDevCouple_I

    GameDevCouple_I

    Joined:
    Oct 5, 2013
    Posts:
    2,158
    Thanks for this! Although we need much much more units and a large play area, so I am currently thinking the only way to do this is:

    1. Build a graph based a star implementation, where the nodes store an "offset" from initial position, and nodes can be updated at runtime to have a new offset. Then use offset within the calculation of position + pathing.

    2. use aron granbergs a* project, which includes moving in the pro version. But underneath it probably does similar things.

    3. do some form of matrix transformation so that all graphs are actually at world centre, and the path is then calculated using an offset based on current pos vs graph pos. This could probably be done using in built navmesh system.

    So far its probably more worthit for me to take the time and build our own, so will likely roll with that
     
    Last edited: May 9, 2018
  14. Cereal_Killa

    Cereal_Killa

    Joined:
    Oct 20, 2013
    Posts:
    205
    I noticed you clicked on the moving platform and then again on the destination, and used the Navmesh link from the moving platform which was only valid when overlapping a second navmesh. I was hoping for more of a long distance moving platform where the platform itself is basically an offmesh link animation (so the target destination is not the platform itself but somewhere on the second mesh), but not sure how to time it with the platform arriving.