I'm curious if you can think of any simple ways to keep the NPCs from walking of ledges?
A navigation mesh which only includes walkable areas with appropriate pathfinding would prevent it from choosing to run off a ledge, but there are reasons to have other kinds of 'local' avoidance behaviors (e.g. don't want a full pathfinding AI, or trying to deal with interference). The extra avoidance behavior could look like checking a ray in front of the character pointing down, looking for cliffs. If it finds any, the character could steer away from the trajectory that would take it off the ledge. The more imminent the fall, the stronger the influence; if it's just about to step off, the influence could be strong enough to immediately reverse direction.
There's a variety of ways you can handle that query, too. You may want to use multiple rays in front and to the sides, like feelers. Another common option is to sample stochastically or incrementally; instead of sending 3 (or however many) rays every single frame, just send one ray each frame from one of the query locations (randomly or otherwise). The aggregate effect of those queries will steer the character away from obstacles at a fraction of the cost.
[Side note: a full CharacterController or SphereCharacterController would be superior to the SimpleCharacterController in almost every way, including performance. If you want maximum performance, use the SphereCharacterController. If you want a character with more height than width but still want as much performance as you can get, you can disable the CharacterController's stepping behavior by commenting these lines in CharacterController.cs:
Code: Select all
if (StepManager.TryToStepDown(out newPosition) ||
StepManager.TryToStepUp(out newPosition))
{
TeleportToPosition(newPosition, dt);
}
Then, you can give the character body a small radius, but set a high collision margin. This makes the character body nearly a capsule. The rounded bottom will allow it to climb over steps without requiring teleportation based stepping.]