Clientsided npc pathfinding system with serverside replication to all clients ... possibe?

So i wrote, or rather, modified, a pathfinding npc script to work purely on the client. My reasons for doing so is that i use a infinite terrain generator, and i have infinite npcs (alltought only a limited number is loaded on the client at the same time )so running raycasting on the client is thousands of times less resource intensive.

My script is written such that if a group of players stay relatively close to another then the npc pathfinding works as if it were serverside with the npcs state and position being pretty much the same on the clients. So, if say 3 players all have the same npc model loaded when the npcs position changes, then the npcs position will replicate more or less similar for all those 3 players. But if now a new player comes in proximity and have the model loaded then his version of the model will be located somewhere else - at the initial position that is specified for the model to appear in.

I wonder, would it make sense or be feasible to send the position from the client, if for example the npc has a specific player as a “target”, to the server and then from the server replicate all clients with the positional data?

Maybe someones already done this … I am hesitant to start programming such a thing cause, well, client->server replication could lead to all sorts of game breaking problems, hackers being one problem.

I should add, my idea of how to secure the replication is to do some maths on the position value - checking if it is possible for the npc at its given speed to move from one direction to the next

This video might give you some ideas and useful info:

1 Like