Forum rules - please read before posting.

NavMeshAgent, NavMeshAgentIntegration with UnityNavigation and possibly terrifying workarounds

Hey everybody.

I am developing a game with Adventure creator 1.67.2 and Unity 2018.3.8f1 in 2.5D.
I have multiple scenes each with their own NavMesh and a Player prefab using a NavMeshAgent and NavMeshAgentIntegration (NMAI from here on). Movement method is set to direct.

I used to have an issue with playerstarts when switching scenes, because I didn't use the NMAI then and the Player wouldn't be properly teleported to its designated playerstart. But it snapped onto the navmesh just how it was supposed to be. Now with the NMAI I ran into another problem. The NMAI disables the NavMeshAgent component of my player (which is exactly what it's supposed to do when you are not using Point and Click Movement). But that means the Player doesnt stick to the NavMesh anymore.

My first approach was to just comment out the line of code in NMAI deactivating the NavMeshAgent. I quickly realised that this wouldn't solve my problem cause after the first scene switch controls got weaker and after 4 switches the player just would always return to it's initial position no matter where I went.

My second (and currently only working approach) was to attach a monobehaviour to the player which activates the NavMeshAgent on update. So technically it's constantly flipping on and off. I cannot stress enough how terrible this feels, but it works so..

I tried only activating the NavMeshAgent on Scene Load but it doesn't do the trick, since the NavMeshAgent needs to continously keep the player on the NavMesh.

So my question is: Is there a better solution?

Comments

  • See the Manual's "Direct movement" chapter - direct control does not rely on pathfinding. The NavMesh Agent should not be used, and the baked NavMesh will be ignored. Attempting to have a direct-control character only move when above a NavMesh would result in motion issues when approaching a NavMesh's edge.

    You instead need to place down "wall" colliders around the walkable areas to prevent the Player character from moving beyond them. This can either be done with standard BoxCollider components, or AC's "Collision" prefab type.

    See the 3D Demo scene for an example, as this is set up to work with both point-and-click and Direct movement. Note that when using Direct movement, pathfinding is used only for NPCs, and Players during cutscenes.

    On the topic of attaching a MonoBehaviour, though: be aware that the NMAI component is not referenced by the rest of AC's codebase, so it is actually possible to duplicate it and modify the copy with whatever changes you wish. It would be feasible to therefore use a variant that doesn't deactivate the NMA component if you so desired.

  • Thank you Chris for this detailed and fast answer!
    I think I dismissed the idea of colliders early on for reasons I don't really remember anymore. I'm going to look into it!

    I haven't had any issues with NavMesh edges so far but I'm gonna do some testing, if this is good enough for my purposes.

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.