Forum rules - please read before posting.

NavMeshSegments holes with Unity Navigation Method

edited February 2015 in Technical Q&A
I'm trying to create a passage that isn't walkable until I put a stick on it.
Using the pathfinding of Unity, I would like to change the NavMeshSegment to NOT walkable in the beginning, and walkable when I put the stick.
With the Object: Transform method isn't working because the Bake it's calculated in the Unity editor, so if I only move the NavMeshSegment the player still walk on that zone...

The only "working" method is to put a big CollisionCube on the Default layer above all the not walkable zone... but it's not very comfortable...

There is another trick I don't get?
Tx and bye!

Comments

  • Your best bet is to basically change the navmesh which is an Action list option.

    There is another option.

    You might want the player to be able to click on the far side of your 'chasm' and then refuse to go there. this is easy. Have the navmesh be the entire place you intend your player to be able to go eventually, including the stick on which they can't yet walk.

    Until the path is 'clear' place a trigger at the place where they WOULD walk off the edge onto the stick.  This trigger can be turned off once they put the stick down.

    What the trigger can trigger is your player stopping and saying something like "I can't jump across there, I need a way across".

    This means if they click on the gap or on the other side the player with TRY to cross but then stop at the edge.
  • Tx @Xidore but the passage have to been secret. 
    Imagine a pier, surrounded by some small island. The only hotspot is "small island". Player have a long wooden board (in the inventory, yep! ^_^),
    If he walk near the pier border, I don't wanna he sayd he can't reach the island. It's too easy to understand he have to use the wooden board.
    When he walk near he don't have to say nothing and cannot pass. 
    Actually if I go near the border, he find the navmesh and he walk on the water (because I already put the wooden board with remember visibility).
    I have think other ways but with no results.
    Where is the action to change the navmesh? I have segments, not a complete navmesh...

    Maybe I can cover the island navmesh with the yellow hotspot cube and the passway over the transparent wooden board with a collision cube set to default... but it's a turnaround... I was thinking that maybe there was a easier way to enable a passage.
  • Well the player's character doesn't HAVE to say anything. Just have them stop at the trigger until the trigger is removed. :)

    If you want the navmesh completely different then just have a two different NavMesh objects in your scene or you could put a hole over the area you want to 'block' and use the Engine: Change scene in an ActionList function required to swap them at the right time.

    From the manual (my underline and bold emphasis):
    "Engine: Change scene setting
    Changes any of the following scene parameters: NavMesh, Default PlayerStart, Sorting
    Map, Cutscene On Load, and Cutscene On Start. When the NavMesh is a Polygon
    Collider, this Action can also be used to add or remove holes from it."
  • Ehehe!
    Yeah, I read this part and if you see it says Polygon Collider. The NavMeshSegments (NMS) aren't polygon collider so it won't work (it also tell me when I choose that option).

    Btw, maybe I find a workaround. I don't create the NMS for the wooden board, I leave that space empty, so the char can't walk on it. When the player put the wooden board, I can activate the trigger Move to path without the pathfinding so he go strait from the other side (or I'll put an animation to make it walk slowly to the other side).

    Tx for your suggestions @Xidore
    Bye

    :)
  • Yes but you can change the navmesh in an Interaction surely? Is there a reason you can't have one navmesh without the board path and then swap it for a navmesh with it?
  • The only reason is I dunno how to change the navmesh with another.
    If I have 10 segments, how can i change them when they were baked in the navigation tab?

  • Good question. I assume you can bake a second navmesh in order to be able to change it. I confess I'm out of my experience because I do my 3D in Maya and my AC game is 2D.

    I'm sure Chris can shed light on what the correct procedure would be to get a 2nd AC baked navmesh to swap out.

  • Well, Unity can't re-bake during runtime, right?  If you want to swap a NavMesh in-game, you'll have to rely on the Mesh Collider method.
  • Yep, just what I was thinking... no problem, I find a workaround, tx for your answer!
  • I know this is not a very recent thread but I thought maybe I would add some info here for those who might be looking for answers in the future.

    So Unity offers two different ways to solve the problem of runtime navigation mesh changes; one using Off Mesh Links and the other using Nav Mesh Obstacles. Let's say you have two separate walkable areas in your scene and you want them to be either connected or disconnected depending on your scene logic.

    With the Off Mesh Links approach you bake the two areas as separate with no connection between them and then you use an Off Mesh Link to connect between the two at runtime. Each Off Mesh Link is composed of two empty game objects to mark the start and end of the link (and you place each of them on a different walkable area) and another empty game object to hold the Off Mesh Link component. As a matter of fact, you can drop the third game object and just add the Off Mesh Link component to any of the first two. It doesn't really matter so it's a matter of choice. Then you drag the start and end game objects onto the Off Mesh Link component, essentially creating a bridge between the two separate walkable areas. As long as this link is active, the player will be able to freely navigate between the two walkable areas. The moment the link becomes inactive, the walkable areas become separate again and the player will not be able to navigate between them. The nice thing about the Off Mesh Link is that its "Activated" state can be switched on or off at runtime from code, which makes it very easy to write a custom Action to do just that.

    Now with the Nav Mesh Obstacles approach, on the other hand, you bake one large walkable area which includes the two previously-mentioned areas and a walkable "bridge" between them. Then you use a Nav Mesh Obstacle to carve a hole in the navigation mesh, breaking the connection between the two areas at runtime. A Nav Mesh Obstacle is essentially an empty game object with a Nav Mesh Obstacle component. You place this game object over that "bridge" area, which creates a "hole" in the large walkable area, breaking it into two separate areas. As long as this obstacle is active, the player will not be able to walk between the two areas. The moment the obstacle becomes inactive, the two separate walkable areas become one again and the player will be able to freely navigate between them. And here too, the obstacle's "Carving" state can be switched on or off at runtime from code, which makes it very easy to write a custom Action to do that.

    Using any of the above approaches, you can easily make changes to how the Unity-baked navigation mesh behaves at runtime so it's very useful to keep in mind when you have doors, bridges or any kind of obstacles in your scenes which require different pathfinding behaviors depending on scene logic.

    Hopefully someone will find this knowledge useful.

  • By the way, I wanted to post here the full code for the two custom Actions I mentioned above but each one of them seems to be too long for posting here as I get a red warning stating just that. Isn't there a way to post code in the forum?
  • edited April 2015
    Thanks for your knowledgement sharing @danielvierna
    During the we i'll try on unity the things you sayd.

    For the Custom Action code, don't you have a dropbox or Mega account to put directly the file with the script on? Then you can share the link here. ;)
  • Sure I have but that link can go broken at any time in the future. It's not the same as posting the actual code on the thread page. I noticed others post code on the thread page as well so I wondered how come I can't do the same. My code is even shorter than the code in this thread so I really don't understand...
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.