Sign in to follow this  

Walking Protocol

This topic is 3629 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is this a good way to handle players walking in an online 2d tile-based game? 1) Player presses key then sends packet to server - move in direction 2) Server checks the next tile in that direction for blockage then moves character 3) Server sends packet to clients on the same map - player moved to x,y 4) Client sends packet to server - done walking animation Loop 2-4 changing destination one tile in the direction until player releases key 1) Player releases key then sends packet to server - stop walking 2) Server stops moving the character then sends packet to the clients on the map - stopped walking The client sending a packet to the server so the server knows when the client is done animating the character walking to the next tile to keep things in sync and the server doesn't get ahead of the client. Walking should be smooth enough that it doesn't look as if the player is walking on a per-tile basis, but I chose to do a per-tile basis because its simpler and less chance of the clients becoming out of sync.

Share this post


Link to post
Share on other sites
It really depends on the kind of game, and the kind of feel you are going for. In my 2d tile-based online game engine, vbGORE (see signature), I did the following:

1. Client receives input for movement, checks if movement can be done (not already moving and tile to move to is not blocked) then starts moving, along with tells the server they started moving
2. Server receives the packet from the client, validates the movement, and starts moving them on the server if valid. If not valid, the server tells the client they need to go back to tile (X,Y) and warps them back there, ensuring the client is correctly synchronized.
3. Server tells all clients in the map that player X is moving from tile (X,Y) in direction D. This ensures that the player starts moving on the correct tile and moves to the correct tile.

Moving across multiple tiles gets a little tricky. I just put in an animation reset delay, so when you move a tile, your animation does not instantly reset to standing still when you stop moving, but instead waits around 100ms for more input. This isn't really noticeable (at least I don't notice it) and keeps things very smooth. Input is only handled when the player has completed their movement - ie, you don't check between the transitions. The server views movement as instantaneous - there is no transitional period from (X1,Y1) to (X2,Y2).

A little clip of it in action can be seen here: http://youtube.com/watch?v=u9_lelKnho8

Its not a flawless system by any means, but it is very basic and does get the job done. Try implementing it and seeing if you need something smoother after you finished it.

Share this post


Link to post
Share on other sites

This topic is 3629 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this