我正在爲我的朋友們開發一款小型遊戲。到目前爲止,我已經獲得了網絡的權利,兩個玩家都可以四處飛翔,並且全部同步。從錯誤玩家射擊的投射物
現在我已經加入彈(激光),我產卵這樣的:
if (_mou.LeftButton == ButtonState.Pressed
&& oldState.LeftButton
!= ButtonState.Released)
{
if (timeSinceShot > timePerShot)
{
timeSinceShot = 0;
bulletRotation = rotation; //Rotation of the players ship
laser.addLaser(myID, bulletRotation, localPosition);
}
}
這工作得很好,它觸發從我的船激光器,但沒有得到顯示呢。
現在,當我火我稱之爲:
om.Write(bulletRotation); //Sends the rotation to the server
而且當服務器收到它,它發回給所有玩家,包括誰開槍的人。
以下是我收到的客戶端上的數據,並將其寫入激光列表:
if (who != myID)
{
try
{
float laserR = msg.ReadFloat();
laser.addLaser(who, laserR, player.players[i].position);
}
catch { }
}
現在,當我測試它在2個客戶端和火,我可以看到自己射擊在第二屆客戶端,它是好。然而,它不僅會觸發第二位客戶,還會觸發我客戶的第二位玩家。
編輯:誰是RemoteUniqueIdentifier和身份識別碼是客戶RemoteUniqueIdentifier
這裏是我的問題的照片。 http://i.stack.imgur.com/CYJyW.png (不能上傳尚未因爲我沒有10代表。)
編輯2:
這是怎樣的服務器時,它的數據發送給所有的玩家:
foreach (NetConnection player in server.Connections)
{
// ... send information about every other player (actually including self)
foreach (NetConnection otherPlayer in server.Connections)
{
// send position update about 'otherPlayer' to 'player'
NetOutgoingMessage om = server.CreateMessage();
// write who this position is for
om.Write(player.RemoteUniqueIdentifier);
om.Write(otherPlayer.RemoteUniqueIdentifier);
if (otherPlayer.Tag == null)
otherPlayer.Tag = new float[4];
float[] pos = otherPlayer.Tag as float[];
om.Write(pos[0]); // velocity X
om.Write(pos[1]); // velocity X
om.Write(pos[2]); // rotation
if (!noLasers)
{
om.Write(pos[3]); // bullet rotation
}
// send message
server.SendMessage(om, player, NetDeliveryMethod.Unreliable);
}
}
玩家中的'i' [i]'??? –
for(int i = 0; i
OK,並且當您調試並設置斷點以放置IF後面時,它會執行多少次? –