Testing Multiplayer Movement
測試多人運動
To test Multiplayer movement we must again have two instances of the game running simultaneously.
為了測試多人游戲每瞒,我們必須再次同時運行兩個游戲?qū)嵗?/p>
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.
從編輯器中運行的實例將與我們的更改同步喳瓣,但是獨立的構(gòu)建將會過時,需要更新我們對項目所做的最新更改土辩。
Build and Run this scene as a standalone application.
構(gòu)建并運行這個場景作為一個獨立的應用程序啼止。
The standalone player will now start and show the in-game UI from the NetworkManagerHUD.
獨立播放器現(xiàn)在將開始并顯示來自NetworkManagerHUD的游戲內(nèi)UI糯耍。
Click the LAN Host button from the in-game UI to start this game as a Host.
點擊游戲內(nèi)UI的局域網(wǎng)主機按鈕周霉,作為主機開始游戲。
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.
游戲?qū)⒃诰庉嬈髦羞\行陡厘,并從NetworkManagerHUD顯示游戲內(nèi)UI抽米。
Click the LAN Client button from the in-game UI to connect to the Host as a Client.
單擊游戲內(nèi)UI中的LAN客戶端按鈕以連接到主機作為客戶端。
There should be two player GameObjects;
應該有兩個玩家的游戲?qū)ο?
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.
目前,他們將處于完全相同的位置谤饭,所以可能出現(xiàn)在場景中只有一個玩家的游戲?qū)ο蟆?/p>
By checking the Hierarchy Window, there should be two Player(clone)’s.
通過檢查層次結(jié)構(gòu)窗口标捺,應該有兩個播放器(克隆)。
To test moving the Client’s player GameObject in the scene:
在場景中測試客戶的播放器游戲?qū)ο?
Press the WASD or arrow keys to move and turn the Client's player
按下WASD或箭頭鍵移動并旋轉(zhuǎn)客戶端的播放器揉抵。
Note how the player GameObjects now move independently of each other.
注意玩家的游戲?qū)ο蟋F(xiàn)在是如何彼此獨立移動的亡容。
Switch back to the Stand Alone player.
切換回獨立球員。
To test moving the Host’s player GameObject in the scene:
測試在場景中移動主機的玩家游戲?qū)ο?
Press the WASD or arrow keys to move and turn the Host’s player.
按下WASD或箭頭鍵移動并旋轉(zhuǎn)主機的播放器冤今。
The two Player GameObjects should now be completely independent of each other and be in sync on both instances of the game.
這兩個游戲?qū)ο蟋F(xiàn)在應該是完全獨立的闺兢,并且在游戲的兩個實例上都是同步的。
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.
對于遠程玩家的游戲?qū)ο蟮囊苿樱赡軙幸环N“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.
值得記住的是桐磁,所有的網(wǎng)絡應用程序都會受到延遲的影響,而且更常見的是翩蘸,在客戶機和服務器之間移動數(shù)據(jù)的速度會受到限制所意。
There are many ways that latency and data transfers can be optimized.
有許多方法可以優(yōu)化延遲和數(shù)據(jù)傳輸。
For example, the NetworkTransform has a Network Send Rate setting which can be used to set how often the NetworkTransform sends synchronization data.
例如,NetworkTransform有一個網(wǎng)絡發(fā)送速率設置扶踊,可以用來設置網(wǎng)絡轉(zhuǎn)換發(fā)送同步數(shù)據(jù)的頻率泄鹏。
The frequency of updates over a network between Clients and Server can have a heavy impact on how a Networked Multiplayer game feels.
客戶端和服務器之間的網(wǎng)絡更新頻率對網(wǎng)絡多人游戲的感覺有很大的影響。
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.
然而秧耗,更重要的是备籽,網(wǎng)絡應用程序有許多方法可以彌補同步上的差異,這些差異是由于純粹的延遲分井,還是由于同步更新的頻率造成的车猬。
These solutions can include interpolation, extrapolation and many other forms of smoothing and prediction.
這些解決方案可以包括插值、外推和許多其他形式的平滑和預測尺锚。
None of these will be covered in this lesson.
這節(jié)課不會涉及這些內(nèi)容珠闰。
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.
需要在狀態(tài)同步發(fā)生的頻率和游戲的性能之間找到平衡伏嗜。
If a game tries to synchronize too much data too often over a network, the performance of the game will suffer.
如果一個游戲試圖通過網(wǎng)絡同步過多的數(shù)據(jù),那么游戲的性能就會受到影響伐厌。
If a game does not synchronize data often enough, then the feel of the game and game-play could suffer.
如果一個游戲不經(jīng)常同步數(shù)據(jù)承绸,那么游戲和游戲的感覺就會受到影響。
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.
在所有的情況下挣轨,需要對同步的游戲?qū)ο筮M行某種形式的解釋军熏,以使所有的客戶在玩的時候感到平滑和同步。
All Multiplayer Networked games are never in perfect synchronization, as this is not physically possible.
所有的多人網(wǎng)絡游戲都不可能完全同步卷扮,因為這在物理上是不可能的荡澎。
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.
兩個或多個遠程客戶端不能在同一時間處于完全相同的狀態(tài),原因是它們之間傳輸數(shù)據(jù)所需的時間画饥。
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.
然而衔瓮,游戲需要感覺就好像它們是最佳玩家體驗的適當同步,即使個別的實例在它們的確切狀態(tài)稍有不同抖甘。
How to do this will be covered in detail in other lessons.
如何做到這一點热鞍,將在其他課程中詳細介紹。
Close the Stand Alone player.
關閉獨立球員。
Return to Unity.
回到Unity。
Exit Play Mode.
退出播放模式犬缨。