Forum rules - please read before posting.

Dynamic 2d NavMesh using AddHole and RemoveHole

edited December 2018 in Technical Q&A

For reasons explained below (skippable if not interested) I'd like to be able to use AC's NavigationMesh AddHole and RemoveHole functions to dynamically modify the 2d Polygon NavMesh at runtime. I've set up a system to do that, and it seems to be working as expected - the hole appears and disappears as requested and Player navigation skirts around the new hole on the fly. However it kinda feels like it might be on the boundaries of AC usage, so are there any potential pitfalls I should look out for?

...

The use case:

In my current game I'm unable to use AC's "FollowSortMap" for anything other than simple flat objects like trees, because all the other elements are 2d forced perspective isometric structures, where actors' positions on the screen have to be calculated based on whether they are "in front" or "behind" each building. That has necessitated writing my own little system, where collisions with the buildings dictate whereabouts in the Sort Order the colliding Player and/or NPCs appear

It took quite a few iterations to get my head around what needed doing, but it's all pretty much working now. It even sets the buildings semi-transparent when the Player moves "behind" one of them

The one extra flourish is to have vehicles moving around the scene too. They're also forced perspective isometric sprites, but with the extra problem that they don't remain static

So, I use more or less the same technique for those as I do for the buildings, except that the vehicles move along pre-defined paths and when they hit an obstacle such as the Player, they come to a halt, and then move off again when the Player moves away

Again, that's all pretty much working, but, in order to prevent the Player from walking "through" them when they're stationary, I use AC's NavigationMesh.AddHole and RemoveHole to dynamically modify the NavMesh on the fly. I'm pretty sure I won't be able to have more than a few vehicles on screen doing that simultaneously, but for a single test vehicle, it all seems to be working as expected, but... are there any potential pitfalls with it? Or maybe even a better way of approaching the problem

Comments

  • The Scene: Change setting Action can be used to modify a NavMesh's holes at runtime - so no, there shouldn't be an issue with calling AddHole / RemoveHole through script.

    You should, however, recalculate the paths of any moving characters at this time in case such a change affects them. Taken from ActionNavMesh.cs:

    foreach (Char _character in KickStarter.stateHandler.Characters)
    {
        _character.RecalculateActivePathfind ();
    }
    
  • cool. thanks chris, i'll add that path recalculation into the mix

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.