Home Forums Dungeon Master – Support Problem with dynamic nav mesh

Tagged: 

This topic contains 5 replies, has 2 voices, and was last updated by vchevalier vchevalier 2 months, 1 week ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #2089

    tuirennder
    Participant

    Hello!

    Here is how my dynamic navmesh looks like:

    navmesh

    – it is misaligned
    – worse, the five mesh chunks of the five-tiles crossed-shape rooms are not connected in the proper way

    Any idea what’s going on?

    Thanks!

    • This topic was modified 2 months, 1 week ago by  tuirennder. Reason: Image editing
    • This topic was modified 2 months, 1 week ago by  tuirennder. Reason: Image editing
    #2096
    vchevalier
    vchevalier
    Keymaster

    Hi tuirennder,

    Nice to meet you!

    Wow, that’s a messed up dynamic navmesh…
    Okay I don’t have a lot of information, so I’m guessing based on the image you sent me…

    Am I right in assuming that the floor are not the elements that have the “room navmesh” scripts (collider, mesh or primitive)?
    Because even if the navmesh is misaligned, it doesn’t seem to have the proper size. Your floor tiles seem bigger than the navmesh.

    Is it possible that you based your navmesh on colliders that are not aligned with the floor? Realigning and rebaking your default navmesh for each room might solve this issue.

    Also I think you allow your straight corridor room to rotate along the y axis. This would explain why the navmesh of one corridor is slightly misaligned on the left and another one on the right. It’s okay to allow rotations for your room, but I would like you to confirm this, so I can consider that there are really only 2 cases of misalignment rather than 4. 🙂

    Another thing to look at: are you using adjustments on your room prefab? (position, rotation or scale) If you use the scale adjustment, it may explain why the navmesh size and floor size doesn’t match. If you are using the scale adjustment also, it won’t work with the dynamic navmesh system because of a Unity limitation (I think I wrote about that in the user guide, I will verify this if you are using the scale adjustment).

    Other than that, off the top of my head, I wonder: have you activated the track navmesh option? If not, try to activate it for a test. If you move your floor prefab around at runtime, does the regenerated dynamic navmesh now matches the floor or does it still have an offset?

    Oh, of course, are you using baked navmesh for each of your rooms?

    Ok, I will let you look into all of that for now. Please keep me informed of your progress!

    Thanks!

    #2097

    tuirennder
    Participant

    Hi Vincent,

    Thanks for looking into this. Your first idea was the good one: collider problem!
    My floor tiles had each a flat box collider. I replaced the box colliders by mesh colliders, and now the navmesh looks much better:

    navmesh 2

    Now from the above screenshot you’ll notice my second problem: properly positioning the navmesh link instances 🙂

    I tried to do like in the village example scene: link a prefab with a ‘room navmesh link’ script inside the room connector.
    The room configuration look like this:

    Room config

    But I don’t get how you manage to save the adjusments for each instance of the navmesh link for each connector point.

    I think it will work if I simply add the navmesh links directly to the room prefab, but that would be more elegant to do it with
    the connectors 🙂

    • This reply was modified 2 months, 1 week ago by  tuirennder. Reason: edit image links
    #2099
    vchevalier
    vchevalier
    Keymaster

    Cool! I’m glad we solved one issue! 🙂

    I agree with you, it’s more elegant to have the navmesh links included in the connectors.

    Okay judging from the image you posted with your navmesh links, it looks like they are pretty wide but not very long. Navmesh links work best when they have a good margin around them both on the starting point and the destination point. You see the little “X” that appear in the middle of your navmesh link? I think this is in fact two heads of a bidirectional arrow. There are so close to one another that they look like an “X”.

    I suggest you play around with your navmesh link attributes to see how this arrow works. To do this easily, drag’n’drop one of your rooms in the scene at design time. Use the buttons on the room script to render the room prefab and render one of the room connectors with a navmesh link. Now, select the navmesh link script and play with the length of the link. You can input big values for testing: something like 10 units long. You should see the arrow draw itself more clearly. Now that you see the actual arrow, you can rotate your link so that it points toward the next room (because now it looks like your links are actually pointing from the one side of your room to the other, rather than crossing the gap between two rooms).

    Don’t be afraid to put the arrow’s destination point pretty far out in the next room, like I said, these like to have some margin. When it works well, you can then reduce the margin until it looks more natural.

    Try this out and let me know how it runs out!

    Good luck! 🙂

    • This reply was modified 2 months, 1 week ago by vchevalier vchevalier.
    #2101

    tuirennder
    Participant

    OK got it! Basically I missed the fact that each room connector has local adjustment settings for their instantiated elements:

    Local adjustments

    Now everything is at the right place:

    navmesh ok

    After that, I had to solve another problem. It’s not the dungeon master’s fault, but other people using dynamic navmesh will run into it as well so let’s share a solution here 🙂

    It seems that by default when a navmesh agent is crossing a navmesh link, it will be translated on the other side at twice the normal agent speed: so your character will appear to quickly dash accros the navmesh links (or maybe jump if your character can jump).

    To fix is that you have to take control of the movement over the navmesh link. Luckily, Unity already wrote the code for us:

    NavMeshAgent.CompleteOffMeshLink

    Newer version of the script on github:

    AgentLinkMover.cs

    You just need to attach this script to your character and chose if you want a parabolic movement, a teleport, a normal one, …

    Unfortunately the NormalSpeed method is buggy, at least for me, it never gets out of the while (agent.transform.position != endPos) loop. If I do this instead it gets better: while (Vector3.Distance(agent.transform.position, endPos) > 0.1f)
    But I still have seen some occasional glitches.

    Another option that works better for me is to use the Curve method, with a flat curve at height zero and duration of 1 second.

    Cheers!

    • This reply was modified 2 months, 1 week ago by  tuirennder.
    #2103
    vchevalier
    vchevalier
    Keymaster

    Hey, that’s a good looking navmesh. 🙂

    Thanks for providing extra information about navmesh agent behavior. Let me know if you need anything else.

    Good luck with everything!

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.