Home Artists Posts Import Register

Content

Overseer was my first game world to include AI agents. I also used them in Ring of Judgment a few months later. In this post I’ll show you how the AI characters in Overseer work. They are not perfect but I like how they turned out.

The AI in Overseer is very simple. They are called “Pawns” and they are basically just static models that roam the map. They can slide across the ground, spin around to face different directions, and sometimes stand still. But that is enough for the purposes of the game– the challenge is for players to blend in with the Pawns by mimicking this basic behavior.

Programming AI characters is sort of like giving someone a script to follow. Pawn AI behavior essentially boils down to the following script: Every once in a while, choose a random point in the vicinity of a coin, and start walking there. Once you get there, wait a random amount of time, then repeat.” I can use Udon Sharp code to write this script, and give all the Pawn objects the same script to follow. I can also give each individual Pawn some more specific details, like how fast they can move and how fast they can turn as they follow the script.

According to the script, a Pawn will often have to choose some random destination coordinates to move to. To make it easier for players to blend into the crowd of Pawns, I specify in the script that Pawns should prefer to move toward coins. Coins are already randomly placed around the map using a different script- so each pawn just needs to choose a random coin, observe the point in space where it is located, and add a small random amount of error to that point.

What makes AI agents interesting in Overseer is that they can find a path through the map geometry to reach their destination, then slide across the ground to reach it. But how does that work? You have to use a path-finding system.

The Unity engine comes with a built-in system that can move AI characters (“agents”) across a per-calculated ground surface (“Nav Mesh”). There are many other ways to program AI movement from scratch, but I chose to use Unity’s built in version because of the convenience (it handles all the math for you) and it does everything I need (these pawn AI are very simple). There are some things the Unity navmesh system does not handle as easily, for example driving, flying, and moving platforms. If you are making AI that can do these things, you might not want to use Unity’s nav mesh system.

To make a nav mesh agent in Unity, you just have to define how wide it is, how fast it can move, and how fast it can turn. Then, during the game, you can just send it a command: “Go to THIS target location”... and the nav mesh agent does the rest. Super easy!

Instead of walking of physics colliders like players, AI agents walk on a “nav mesh”. The areas where agents are allowed to walk, and which areas connect to each other, can be baked in the Unity editor before uploading the world. In the Overseer world, I specified that agents are only allowed to walk on certain surfaces in the game area, and only connect surfaces if they are close enough together. These settings allow Pawns to slide up stairs, but not drop down from one ledge to a lower ledge. Then I press the Bake button, and Unity shows this nice blue map representing all the surfaces agents are allowed to move on.

To piece everything together, I wrote an Udon script that dictates how Pawns behave, and attached an Udon Behavior with this script to every Pawn object. What’s important is that only the game master is in charge of setting Pawn destinations, choosing when they should move, and synchronizing the position of the Pawn for everyone. Otherwise, the Pawn would be jittering all over the place as your local computer might try to make the Pawn move while receiving conflicting messages from the game master about where the Pawn should be.

Another added quirk is that I wanted pawns to only move forward if they are facing the direction they want to move. By default, Unity nav mesh agents are allowed to move and turn at the same time. But if I allowed Pawns to strafe or twist around corners in this way, it would be difficult for Players to mimic during the game, making it harder for them to blend in. If a Pawn is moving in one direction but facing in a different direction, I drastically lower their speed while they rotate.

I added a “fake lag” feature, similar to how players can sometimes have position lag in VRChat, to make Pawns less easily distinguishable from real players:

The agents in the Ring of Judgment world work in a similar way, except there is no fake lag, and I have some line-of-sight calculations for choosing where to move to, instead of just choosing a random coin to move to!

Files

Comments

No comments found for this post.