Search Unity

Best way to create a path for agent in a cubic puzzle game

Discussion in 'Navigation' started by Juliken, Oct 1, 2018.

  1. Juliken

    Juliken

    Joined:
    Jan 30, 2017
    Posts:
    17
    Hello, I'm actually creating a game with puzzle game phase using cube. Let me explain my problem :
    In this phase I need to move a NavMesh Agent on different heigh. The agent need to detect the best path for him and if he can (or not) climb on the cubes. If the cubes on the map moves the agent need to change his path. I made a schema of the situation.

    What is the best way to set up a system holding everything ?
     

    Attached Files:

  2. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    Well, first off Navmeshes unfortunately don't update automatically, so you'd have to manually update the NavMesh every time a cube changes with NavmeshBuilder.BuildNavMesh(). This is an expensive operation, so you definitely don't want to be doing that every frame. If you have a turnbased game, or the character doesn't move when a block moves, then you shouldn't have problems and can just update the mesh once the block's done moving and then allow the characters to move again.
    As for the navigation itself, if you go to the Navigation window and click the Agent tab, you can set up all parameters for your character's movement. In there there's a parameter called Step Height. If you set this to be exactly as high as your blocks, then the character will be able to "walk up" exactly one block at a time.
    Keep in mind that this will look weird, with your character "sliding up" to the next platform as if there were a ramp.
    if that doesn't work for you, you might have to use the off-mesh link system to generate connections between block surfaces that are short enough for your character to jump, and make your character use those to jump up.
     
  3. Juliken

    Juliken

    Joined:
    Jan 30, 2017
    Posts:
    17
    Thank you for your answer !

    I tried the heighstep and it works really well. This is exactly what I wanted. For the update of the NavMesh I think I will not have problems because I need to update it only when a cube moved.

    My next problem now is to detect particular case like a hole between 2 blocks that allow some agent to jump and not the other. I was thinking of creating a 3D array to stock all the blocks in the scene (something like 6x6x4) and detect when a hole is between 2 blocs to create a NavMeshLink between blocks. Is it possible to create in runtime a NavMeshLink at the right position and make it usable for some of the agents ?
     
  4. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    I did a quick search and the experimental NavMesh Components have a NavMeshLink component, meaning it can definitely be instantiated at runtime. According to the documentation there is an Agent Type field on this component, which should be capable of doing exactly what you want.
     
  5. Juliken

    Juliken

    Joined:
    Jan 30, 2017
    Posts:
    17
    Ok tanks you for your help. I'll work on it !
     
  6. newjerseyrunner

    newjerseyrunner

    Joined:
    Jul 20, 2017
    Posts:
    966
    I’ve been using offmeshlinks for moving and semi solids and they seem to work. Agents don’t go over the link if the gameobject it’s attached to is disabled.
     
  7. Juliken

    Juliken

    Joined:
    Jan 30, 2017
    Posts:
    17
    Thanks for your advice ! I managed to create a system that works well using a 3D array that can holes in the level and create NavMeshLink on top of it.

    Unfortunately the game designers have changed their minds ans my system isn't necessary anymore.