Search Unity

Level of Detail but for AI?

Discussion in 'Scripting' started by Censureret, Mar 17, 2021.

  1. Censureret

    Censureret

    Joined:
    Jan 3, 2017
    Posts:
    363
    I was wondering what the best practice is for having many AI agents with a "sort of" complex controller.

    So in the game, I am creating, you can be in either 3rd person or a free look camera option. The goal is to have about 100 - 200 units on the screen at the same time.

    Now many of these units are "duplicates," so I can achieve a lot with GPU instancing.

    My AI units have a "sort of" complex character controller. As mentioned above, I have a 3rd person view where the player interacts with the unit. Therefore, the unit must be "complex" enough to engage with the player in an interesting way.

    However, since this isn't 100% of the case, there could potentially be a version of the same AI agent with a "smaller" more dump controller that would move the agent correctly but disregard everything else.


    When thinking of this, I thought, "there must be some golden rule to all of this," so what is best practice, and can this be achieved in unity?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,752
    The golden rule is "the player doesn't care what's happening outside his immediate vicinity, so don't bother to simulate it."

    "WHAT WHAT WHAT!? WHAT ABOUT SIDE QUESTS WHERE YOU HAVE TO WAIT AND MEET A CHARACTER LATER TO CONTINUE YOUR QUEST!?"

    All that is true, but generally handled by just checking time periodically and spawning the NPC at that new destination, such as meeting the thieves guild guy at midnight out by the old mill road.

    You either spawn him there when the clock says to, or if the player is close by, you make the guy walk from a little ways offscreen. Those are just level design issues related to how to spawn him. Or just make him blink into existence.

    BUT... if you must simulate 200 visible guys, make a hierarchy of behaviors. NPCs just wander randomly until you come close enough to them to make them possibly interact with you. If you want NPCs to chitty-chat among themselves just keep up with the wandering randomly, and periodically check if nobody is chitty-chatting, and if so start picking random NPCs far from the player and have them check for nearby NPCs to talk to.

    Either way, when it's far away and less interesting, you can check far less often, perhaps only running the AI every five seconds or so.
     
  3. Censureret

    Censureret

    Joined:
    Jan 3, 2017
    Posts:
    363
    Hello :) Thank you for your response.

    My current approach is to keep the AI code such as NavMesh, and the AI logic on a base game object then if the camera is close enough then it switches to the move expensive character controller.

    What do you think about this approach?
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,752
    Anything that gives you the desired result without busting performance or being difficult to work with seems reasonable to me.