I'm developping a game where the user can walk in a room (with the others players). There are some obstacles that blocks the user. I'm using a Javascript pathfinding library to find where the user can walk. But the question is:
Should I use the pathfinding library Client side or server side? Why?


Client-side greatly reduces your costs. The server is doing less calculation, so you need less server power per player. Assuming you want to display the path to the client, doing the calculation server side requires you to send the whole path down in one big chunk, while doing it on the client only requires sending up the actual movements (which is about what you'd require in bandwidth anyway).

There are several downsides to doing it on the client. Their severity depends on your game. If the player is controlling squads of AI agents in PvP games (e.g., an RTS) then client-side pathing would allow clients to gain unfair advantages by modding their client. There may also be lag issues resulting in less-satisfying paths/movement in environments rich with dynamic obstacles.

You've told us nothing about your game that helps to inform the decision, but as an educated guess, I'd suggest doing pathing on the client. Just remember to always make movements validated on the server so the player can't send up illegal moves and warp though walls or such.

  • \$\begingroup\$ "then client-side pathing would allow clients to gain unfair advantages by modding their client" - easily avoided in RTS by using lockstep and parallel logic execution on each players machine. \$\endgroup\$ – Kromster Mar 23 '16 at 5:25
  • \$\begingroup\$ @KromStern: no, still possibly unfair (though probably unlikely to be unfair), as players with unmodded clients may have worse paths selected. e.g., a modded client might calculate more heatmaps to select safer or more advantageous paths while the default client might just always pick the shortest path. Doing this with server-side paths requires clients to send up individual step-by-step move commands for every unit, which may run afoul of bandwidth limits and render the mod infeasible. \$\endgroup\$ – Sean Middleditch Mar 23 '16 at 7:05
  • 1
    \$\begingroup\$ I'm keeping in mind lockstep RTS where clients only exchange with player's input. If clients will calculate the game's state differently, state mismatch will break the game (de-syncing clients). \$\endgroup\$ – Kromster Mar 23 '16 at 7:21
  • \$\begingroup\$ @KromStern: gotcha, that makes sense. \$\endgroup\$ – Sean Middleditch Mar 23 '16 at 16:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.