NPCs!


I added the first NPC today after a couple days delay due mostly to power outages.  Server controlled NPCs are quite challenging because every other player needs to see the same thing (e.g. locations and animations), and the AI for the NPC is 100% on the server, so all the processing loops must be correctly coordinated.

The other challenging thing is waypoint finding and player chasing, or really movement in general.  The server needs to know every possible point that the NPC can move to.  There's no practical way to export the rendered terrain from UE4, and much of it is tessellated, so using the base heightmap created from world machine will provide unacceptable errors even with some lerping.  In order to deal with this, I've created a mysql table to store "valid points" on a 50cm grid, with a special hashing mechanism to quickly access the data at server start time.  The grid is built from players walking around and leaving database breadcrumbs everywhere they go.  I also implemented an NPC explore mode which makes the NPCs pathfind everything in a 60m^2 area and report their position back to the server.  This will allow me to collect all the relevant points for NPCs so that they can waypoint/patrol, pathfind during aggro and flee appropriately.  The server is using a modified A* routine to pathfind every 50ms during chasing and it constantly broadcasts NPC positions as the pathfinding is ongoing.

The interesting thing will be to see how this performs at scale.  The map is 16km^2, so a 50cm grid is going to be quite large.  Server startup/database load time may become an issue if not properly optimized.  I may need to move to a text file or use some kind of compression.  I will probably also thread the navmesh load routine.

Get Darkfire

Download NowName your own price

Leave a comment

Log in with itch.io to leave a comment.