Movement “algorithm” in client-server Multiplayer (MMO) Games?

会有一股神秘感。 提交于 2019-12-03 06:51:31

My initial design would be similar to yours, but if that's not working, perhaps you could allow the client to do ALL the movement and just have the server do some range checking.

So if your last reported position was X, the next one must be within a radius from X where the radius is based on the difference in timestamps sent from the client with the x,y data.

Mostly this is just needed to detect cheating.

Stopping, fighting, etc would require a position be sent along with the attack, and actions triggered by positions would only be triggered after the client sent the update for that position but would be server-based.

Not sure this would help too much, but it might stop the jolting resyncs you would see from your initial algorithm.

Comment response:

No, the clients would still inform the server of their position, but the server wouldn't try to calculate the next position. This would mean that the server (and all other clients) would be at least one send/receive cycle behind in position.

I guess I'm saying just let the client do all the work, figure out where the character is and tell the server, but include enough info that the server can optionally check validity to ensure nobody's cheating.

The cheat detection could even be turned off for performance or set to randomly check.

Note: All collision/position info on objects within traveling range would need to be sent to the client for this to work.

There are 2 ways I can think of doing this - have the client issue commands to the server & the server will be the ultimate map keeper.

Or, keep the maps in the clients, & the clients will have to establish connections with other clients they're "near" in order to do movement, with recordkeeping being done by the server & checked by a few peers (hacker police).

Interesting to me is the possibility to monitor peer connections, and peers that have a latency above a certain threshold just won't show up in the game.

Is your server so slow that it cannot handle all of the movement? Especially in a 2-d game? Typically when I make little 2d games the server gives me back all of my movements, so no calculation is required on the client. If the server begins to lag, I simply freeze up a bit, which is what one would typically expect anyway (although this almost never happens).

In any case, I would definitely see how the performance is without the client making any actual calculations itself. If the performance isn't good enough, see if looping through player movements on the server is causing the delay (and start using a different thread for each client).

If there is indeed a real restriction in bandwidth (movements themselves pass very little data), then certainly you need to find the average delay of that particular user and calculate that into the algorithm. However, to continuously keep finding the average (for precision), you'll have to continue to ping the server to find the round-trip time, which shouldn't be all that costly.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!