Search code examples
unreal-engine4unreal-engine5

Move pawn/character to random point within specific area on the map


I'd like to add some sort of "properties" to different areas of the level so they can affect NPC behavior.

Level layout: level layout

What NPC behavior I want to achieve:

  1. NPC can freely walk around Area #1
  2. NPC isn't allowed to go to Area #4 in general but it may decide to go there in some exceptional cases
  3. If NPC wants to interact with the player he has to go to Area #2 and check if player is in Area #3. If player is not there, NPC have to wait until player enters Area #3

I know that I can affect the path NPC chooses by using navigation modifier volumes and changing navigation cost in some areas.

But, based on goals above, I also need at least the following

  1. I need to get random point within specific area (for goals #1 and #3)
  2. I need to check if some actor is in specific area (for goal #3)

And I guess I don't really need "navigation cost" feature, since if I could get random point in specific area, I would be able to control where NPC goes anyway

The questions are:

  • What actor should I use to mark some areas as "NPC can go here if they want to walk around", "NPC can go here if they want to interact with player", etc?
  • If volume is the best option, what volume should I use? My concerns about Navigation Modifier volume is that I don't really need to modify navigation process by blocking it completely or adjusting its cost.

Solution

  • I have used the NavMeshBoundsVolume to define the area that my AI character is allowed to be in.

    Then I used blackboards and set points the AI could walk around too, adding variables enabling or disabling a point. In your case you could have a variable that is true when the player is in area #3. Example of blackboard with keys

    I've included a picture of my Behavior Tree, so that you can get an idea of the how a flow might look. This is for an "enemy," but you could simply have the AI follow the character to a specific area instead of playing the attack animation and applying damage. Behavior Tree

    Here is a really good series on AI in Unreal Engine. It's UE4 but if you are familiar with the engine you shouldn't have a problem applying it to UE5.