From ee98a17df6d0190a821dd417b9e6e25f378623f1 Mon Sep 17 00:00:00 2001 From: Guilherme Carvalho Date: Wed, 13 Sep 2023 11:19:18 -0300 Subject: [PATCH] fixed multiple players issue --- index.html | 2 +- src/index.ts | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/index.html b/index.html index 8c83d13..917a86f 100644 --- a/index.html +++ b/index.html @@ -11,7 +11,7 @@
- + diff --git a/src/index.ts b/src/index.ts index 724395b..4306ff6 100755 --- a/src/index.ts +++ b/src/index.ts @@ -64,6 +64,8 @@ class App { this.username = 'Guest'; + this.loginForm['elements'][0].value = window.location.hostname === 'localhost' ? 'http://localhost:8080' : 'https://best-multiplayer-game-possible-pvenbf56dq-uc.a.run.app'; + this.loginForm.addEventListener('submit', e => { e.preventDefault(); @@ -163,20 +165,18 @@ class App { parseRoomPlayers(newRoomData: Room) { for (const player_id in newRoomData.players) { - if(player_id === this.localPlayer.username) { - continue; - } - const newPos = new Vector3(newRoomData.players[player_id].position._x, newRoomData.players[player_id].position._y, 0); const newRot = new Vector3(newRoomData.players[player_id].rotation._x, newRoomData.players[player_id].rotation._y, newRoomData.players[player_id].rotation._z); // Player already exists if(this.currentRoom.players[player_id] && this.currentRoom.players[player_id] instanceof Player) { this.currentRoom.players[player_id].update(newPos, newRot); - return; + continue; } - const newPlayer = Object.assign(new Player(player_id, this.scene, false), newRoomData.players[player_id]); + const isLocal = player_id === this.localPlayer.username; + let newPlayer = new Player(player_id, !isLocal ? this.scene : undefined, isLocal); + newPlayer = Object.assign(newPlayer, newRoomData.players[player_id]); newPlayer.update(newPos, newRot); this.currentRoom.players[player_id] = newPlayer;