Testing Multiplayer Movement
测试多人运动
To test Multiplayer movement we must again have two instances of the game running simultaneously.
为了测试多人游戏,我们必须再次同时运行两个游戏实例。
The instance being run from the editor will be up-to-date with our changes, but the standalone build will be stale and needs to be updated with the most recent changes that we have made to the project.
从编辑器中运行的实例将与我们的更改同步,但是独立的构建将会过时,需要更新我们对项目所做的最新更改。
Build and Run this scene as a standalone application.
构建并运行这个场景作为一个独立的应用程序。
The standalone player will now start and show the in-game UI from the NetworkManagerHUD.
独立播放器现在将开始并显示来自NetworkManagerHUD的游戏内UI。
Click the LAN Host button from the in-game UI to start this game as a Host.
点击游戏内UI的局域网主机按钮,作为主机开始游戏。
We should see the game running with one player GameObject in the scene.
我们应该在场景中看到一个玩家在游戏中运行的游戏。
Return to Unity.
回到Unity。
Enter Play Mode
进入播放模式
The game will now run in the editor and show the in-game UI from the NetworkManagerHUD.
游戏将在编辑器中运行,并从NetworkManagerHUD显示游戏内UI。
Click the LAN Client button from the in-game UI to connect to the Host as a Client.
单击游戏内UI中的LAN客户端按钮以连接到主机作为客户端。
There should be two player GameObjects;
应该有两个玩家的游戏对象;
one for the local player on the Host and one for the remote player for this Client.
一个用于本地播放器,另一个用于该客户端的远程播放器。
Currently, they will be in the exact same position, so it may appear that there is only one player GameObject in the scene.
目前,他们将处于完全相同的位置,所以可能出现在场景中只有一个玩家的游戏对象。
By checking the Hierarchy Window, there should be two Player(clone)’s.
通过检查层次结构窗口,应该有两个播放器(克隆)。
To test moving the Client’s player GameObject in the scene:
在场景中测试客户的播放器游戏对象:
Press the WASD or arrow keys to move and turn the Client's player
按下WASD或箭头键移动并旋转客户端的播放器。
Note how the player GameObjects now move independently of each other.
注意玩家的游戏对象现在是如何彼此独立移动的。
Switch back to the Stand Alone player.
切换回独立球员。
To test moving the Host’s player GameObject in the scene:
测试在场景中移动主机的玩家游戏对象:
Press the WASD or arrow keys to move and turn the Host’s player.
按下WASD或箭头键移动并旋转主机的播放器。
The two Player GameObjects should now be completely independent of each other and be in sync on both instances of the game.
这两个游戏对象现在应该是完全独立的,并且在游戏的两个实例上都是同步的。
When running two instances of the project, the remote player GameObject may not appear to be moving smoothly on the local client.
在运行项目的两个实例时,远程player GameObject可能不会在本地客户机上顺利地移动。
There may be a “steppy” feel to the movement of the remote Player's GameObject.
对于远程玩家的游戏对象的移动,可能会有一种“steppy”的感觉。
It is worth keeping in mind that all networked applications will be affected to some degree by latency and, more often, the limitations to the speed in which data can be moved moved between the Clients and Server.
值得记住的是,所有的网络应用程序都会受到延迟的影响,而且更常见的是,在客户机和服务器之间移动数据的速度会受到限制。
There are many ways that latency and data transfers can be optimized.
有许多方法可以优化延迟和数据传输。
For example, the NetworkTransform has a Network Send Rate setting which can be used to set how often the NetworkTransform sends synchronization data.
例如,NetworkTransform有一个网络发送速率设置,可以用来设置网络转换发送同步数据的频率。
The frequency of updates over a network between Clients and Server can have a heavy impact on how a Networked Multiplayer game feels.
客户端和服务器之间的网络更新频率对网络多人游戏的感觉有很大的影响。
More importantly, however, there are many ways that a Networked application can cover for discrepancies in synchronization, whether these discrepancies are from sheer latency or due to the frequency of synchronizational updates.
然而,更重要的是,网络应用程序有许多方法可以弥补同步上的差异,这些差异是由于纯粹的延迟,还是由于同步更新的频率造成的。
These solutions can include interpolation, extrapolation and many other forms of smoothing and prediction.
这些解决方案可以包括插值、外推和许多其他形式的平滑和预测。
None of these will be covered in this lesson.
这节课不会涉及这些内容。
At this point, it is worth bearing in mind a few key points.
在这一点上,值得考虑几个关键点。
A balance will need to be struck between how often state synchronization happens and the performance of the game.
需要在状态同步发生的频率和游戏的性能之间找到平衡。
If a game tries to synchronize too much data too often over a network, the performance of the game will suffer.
如果一个游戏试图通过网络同步过多的数据,那么游戏的性能就会受到影响。
If a game does not synchronize data often enough, then the feel of the game and game-play could suffer.
如果一个游戏不经常同步数据,那么游戏和游戏的感觉就会受到影响。
In all cases there will need to be some form of interpretation of the synchronized GameObjects to keep all Clients feeling smooth and in sync while playing.
在所有的情况下,需要对同步的游戏对象进行某种形式的解释,以使所有的客户在玩的时候感到平滑和同步。
All Multiplayer Networked games are never in perfect synchronization, as this is not physically possible.
所有的多人网络游戏都不可能完全同步,因为这在物理上是不可能的。
Two or more remote Clients cannot be in the exact same state at the same time due simply to the time it takes to transfer the data between them.
两个或多个远程客户端不能在同一时间处于完全相同的状态,原因是它们之间传输数据所需的时间。
Games, however, need to feel as if they are in proper synchronization for the best player experience, even if the separate instances are slightly different in their exact state.
然而,游戏需要感觉就好像它们是最佳玩家体验的适当同步,即使个别的实例在它们的确切状态稍有不同。
How to do this will be covered in detail in other lessons.
如何做到这一点,将在其他课程中详细介绍。
Close the Stand Alone player.
关闭独立球员。
Return to Unity.
回到Unity。
Exit Play Mode.
退出播放模式。