Jump to content

Timing movement events on a server


Recommended Posts


I've built a simple client much like a basic version of BrowserQuest, where you can select a tile, and the game will generate a path. This path is turned into a lovely tween chain, and the player will stroll down it until it reaches his destination.

Now I'm wanting to transfer path generation to the server. I haven't built that part yet, but for the sake of this topic lets pretend I did. So now I have this lovely array of tiles the player need to go to.

So everything is all fine and dandy, until I realize that simply telling all clients what tiles the player is going to isn't going to cut it. 
Mainly because if the player tries to move to another location while in the middle of going to a target tile (mid tween) it will drop it's current tween and move to the new target tile. 
The problem with this is the server has no understanding of the location of the player, just it's path. So I need to somehow time events on the server (calculate where they should be at a certain time) to make sure the player isn't cheating.

But of course, the server data lags. So everything is screwed up! How do you think I should do this? One possibility is whenever the player requests something (ie "move here" or "attack this" or "pick up this item", and was moving a while back, to calculate where they should be by now, plus or minus half a tile or so due to lag. 

Other than that, not quite sure. Thank god this game has no physics and is just tile based :D

Link to comment
Share on other sites

I dont see any real issue with 'close enough' being ok, getting things exact would be mega hard and you don't need the accuracy.

I only see one issue, where the path becomes block during the duration of the movement, the server, of course, should be able to pick this up because it knows the location of all entities at all times but it would depend on how granular you have the simulation. It sounds like you work out the path on the client and then send it along to the server, why don't you do that work on the server? This way the client is dumb and the server becomes your single source of truth, this makes many things much easier. So the client just sends a coordinate that they want to travel to and the server responds, you could duplicate this on the client if its too slow but the server takes precedent if there is any conflict.

This way the server advances the simulation each tick, as your client should be (it might not need to be every tick on the server, depending again on granularity), now the server knows all positions and you just need to define what happens when the path is blocked i.e. does the entity stop? or recalculate? or just wait until it is unblocked? whatever your decision it needs to be consistent. Of course, client and server can (and probably should) sync up more regularly than the duration of the entire movement so any discrepancies in position can be rectified before they get too large.

Link to comment
Share on other sites

Yeah, as I said I plan on transferring path generation from the client to the server.

I'll look into calculating by ticks, although I'm thinking this may not be required (only calculating when I need to instead of every tick)

I guess if the path gets blocked, the server will have to recalculate the path and send it over. 

Thanks a lot!

Link to comment
Share on other sites

Well I got it working!
What I did was whenever the client requested to move to a new tile, the server calculated the path and sent it to all the clients, and clientside the players would walk along the path. (Tween chain)

Server side, it goes step by step using setTimeout, and updating all clients the new server x and y

If the Server's reported coordinates are too far away from the client's coordinates, it will automatically fix it all up.

And if the client decides to go to another tile while still on a path, the path will be canceled on both clientside and serverside.

Thanks so much for all the help guys!

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...