Synchronizing AI NPCs on a multiplayer game
I've started developing a small multiplayer racing game, obviously we're using all the player prediction, dead reckoninng and lag compensation techniques that Half Life, Quake and Unreal use - however we plan on having dozens of AI cars in the game as well.
Initially we decided to simply send a random seed to all clients and they will calculate AI positions, etc - however, we've reached the following problem:
- All clients receive a seed to run AI cars
- Clients only receive movement updates for players within their line of sight
- Player A hits an NPC car
- Player B enters player A's frame
Now since player B didn't receive player A's movement, he'll assume the AI car is still moving as it should, and wouldn't calculate in the fact that playe开发者_JS百科r A hit one of those cars...
So long story short - how can you synchronize AI units that were affected by players?
Presumably, your server is aware of any collisions. In that case, simply notify all your clients of collision results--essentially re-seeding the AI on the clients, at the point of the collision, with the new directions, velocities, RNG seeds, etc.
精彩评论