在 XNA 中通过网络同步游戏精灵
我正在制作一个两人 3D 游戏,需要同步远程玩家的位置。只有一个对象,即代表玩家的化身,需要在两个游戏之间同步。
我认为这非常简单,但事实证明,即使在本地网络中,远程玩家在两台不同的机器上玩游戏时也会出现卡顿的情况(同一台机器上的游戏的两个实例看起来不错)。
在当前方法中,一个游戏是服务器,而另一个游戏则充当客户端,通过专用端口以文本字符串形式发送坐标。基本上,每次化身实际移动时,它们都会将化身坐标传输给彼此。
知道如何解决发送/接收坐标时与滞后相关的问题吗?只需要在本地网络上工作。
I'm making a two player 3D game, and need to synchronize the location of the remote player. Only one object, the avatar representing the player, needs to be synchronized between the two games.
I thought this would be pretty straight forward, but it turns out even in a local network the remote player is moving in a stuttery way when playing on two different machines (two instances of the game on the same machine looks fine).
In the current approach one game is the server, while the other acts as a client, sending coordinates as text strings over a dedicated port. They are basically streaming avatar coordinates to each others, each time the avatar is actually moving.
Any idea how resolve lag related issues when sending/receiving coordinates? Only needs to work over a local network.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Glenn "Gaffer" Fiedler 关于游戏程序员网络的系列文章几乎都是热门内容-基本游戏网络编程指南。他还有一篇关于网络物理的文章。
该系列文章中描述的许多技术(例如:可靠性)已在 利格伦。
基本上,您要使用的技术是插值、外推和预测。 这篇文章,以及网络物理文章。基本上,您采用不可靠、滞后的位置数据流,并使用它对对象的实际路径进行视觉上合理的估计。
Glenn "Gaffer" Fiedler's series of articles on Networking for Game Programmers are pretty much the go-to guide for basic game network programming. He also has an article on Networked Physics.
Many of the techniques described in that series of articles (eg: reliability) are already implemented for you in libraries like Lidgren.
Basically the techniques you want to use are interpolation, extrapolation and prediction. There's a good explanation of them in this article in the aforementioned series, plus the Networked Physics one. Basically you take the unreliable, laggy stream of position data, and use that to make a visually plausible estimate of the actual path of the object.