Strategies for real-time networked player movement
Posted: Sun Apr 06, 2014 7:40 pm
So in my new project idea I need real-time player movement but not with absolute time accuracy. Instead, movement is going to be tile-based (to those not familiar, it means your character is always lined-up to a tile, much like old school NES RPGs), with no twitch-based gameplay. So obviously right there that relaxes the requirements a bit, but it still needs to be accurate of course or the server and clients will keep getting out of sync and players will be doing the "EQ jitters" all over the place as the server keeps overriding the client and moving them around.
Anyway, I am trying to decide whether to go with movement keys or click-to-move. This is a classic resource trade-off. Movement keys is more bandwidth intensive, but less intensive on server CPU resources. Click-to-move is much easier on bandwidth, but harder on server CPU resources. Since the server CPU is quite a deep well compared to bandwidth, I am leaning heavily towards click-to-move. I also think it fits the general idea a bit better. Here are the two general algorithms:
For live movement:
1. A player presses movement key.
2. Client immediately lets them move.
3. Client sends message to server that player is moving in that direction.
4. Server sets direction flag on that player's data store.
5. On update loop, room info is processed, sending all players in that area notification that that player is moving in that direction.
6. Client makes other players see that player as moving.
7. On key up, client makes player stop moving.
8. Client sends message to server that player has stopped moving in that direction.
9. Server removes direction flag on that player.
10. On update loop, room info is processes, sending all players in that area notification that that player is no longer moving.
11. Client makes other players see that player has stopped moving.
12. Server validates with client that player is in the right cell.
13. If there is a problem, client updates to server location.
14. Server sends out validation location to all other players in area, who correct that player to that cell if needed.
For click-to-move:
1. A player clicks an open cell to move.
2. The client detects if the cell is an acceptable cell to try to move to (if not, notify user can't move there and abandon).
3. Perform A* or variant on client, and make sure the cell can be reached (if not, notify the user can't move there and abandon).
4. If the user can move there, perform the movement animations and send the clicked cell to the server.
5. On the server, make sure if the cell is an acceptable cell to try to move to (if not, send a rejection notice to the client and return them to initial cell).
6. Perform A* or variant on server, and make sure the cell can be reached (if not, send a rejection notice to the client and return them to initial cell).
7. Store the movement map list from A* on moving player's data store.
8. Send results to any player that was in the same area to see movement.
9. Perform the animations to move player on observing players' clients.
Does anyone see any problems with either of these methods? And yes, in the click-to-move, there will be a slight delay with observers seeing the other player's moving, but that is fine. The "more CPU intensive" part of click-to-move comes in at using A* on the server. Nothing in the movement keys strategy would be nearly as CPU intensive. But I think node can handle it just fine. It may not even be that much more intensive, since I am unsure what the actual overhead for each Socket.io event is under the covers in node, of which there would be many more with movement keys and could possibly add some serious weight to the movement key strategy.
Anyway, I am trying to decide whether to go with movement keys or click-to-move. This is a classic resource trade-off. Movement keys is more bandwidth intensive, but less intensive on server CPU resources. Click-to-move is much easier on bandwidth, but harder on server CPU resources. Since the server CPU is quite a deep well compared to bandwidth, I am leaning heavily towards click-to-move. I also think it fits the general idea a bit better. Here are the two general algorithms:
For live movement:
1. A player presses movement key.
2. Client immediately lets them move.
3. Client sends message to server that player is moving in that direction.
4. Server sets direction flag on that player's data store.
5. On update loop, room info is processed, sending all players in that area notification that that player is moving in that direction.
6. Client makes other players see that player as moving.
7. On key up, client makes player stop moving.
8. Client sends message to server that player has stopped moving in that direction.
9. Server removes direction flag on that player.
10. On update loop, room info is processes, sending all players in that area notification that that player is no longer moving.
11. Client makes other players see that player has stopped moving.
12. Server validates with client that player is in the right cell.
13. If there is a problem, client updates to server location.
14. Server sends out validation location to all other players in area, who correct that player to that cell if needed.
For click-to-move:
1. A player clicks an open cell to move.
2. The client detects if the cell is an acceptable cell to try to move to (if not, notify user can't move there and abandon).
3. Perform A* or variant on client, and make sure the cell can be reached (if not, notify the user can't move there and abandon).
4. If the user can move there, perform the movement animations and send the clicked cell to the server.
5. On the server, make sure if the cell is an acceptable cell to try to move to (if not, send a rejection notice to the client and return them to initial cell).
6. Perform A* or variant on server, and make sure the cell can be reached (if not, send a rejection notice to the client and return them to initial cell).
7. Store the movement map list from A* on moving player's data store.
8. Send results to any player that was in the same area to see movement.
9. Perform the animations to move player on observing players' clients.
Does anyone see any problems with either of these methods? And yes, in the click-to-move, there will be a slight delay with observers seeing the other player's moving, but that is fine. The "more CPU intensive" part of click-to-move comes in at using A* on the server. Nothing in the movement keys strategy would be nearly as CPU intensive. But I think node can handle it just fine. It may not even be that much more intensive, since I am unsure what the actual overhead for each Socket.io event is under the covers in node, of which there would be many more with movement keys and could possibly add some serious weight to the movement key strategy.