EmbeddedFPSExample
EmbeddedFPSExample copied to clipboard
Server Spawn Location Issue
Please note that when calling GetSpawnDataForAllPlayers(), in unity the last player position added will be (0,0,0).
This is because unity has not completed the frame and therefore the game object has not been instantiated.
So adding this line will fix the issue:
playerSpawnData[playerSpawnData.Length - 1].Position = position;
public void Initialize(Vector3 position, VGS_ClientConnection clientConnection) { this.clientConnection = clientConnection; Client = clientConnection.Client; this.clientConnection.Player = this;
currentPlayerStateData = new PlayerStateData(Client.ID, 0, 0, position, Quaternion.identity);
InputTick = VGS_RegionManager.Instance.region.serverTick;
var playerSpawnData = VGS_RegionManager.Instance.region.GetSpawnDataForAllPlayers();
// Because the player instance not actually instantiated we need to pick up the transform from position
playerSpawnData[playerSpawnData.Length - 1].Position = position;
using (Message m = Message.Create((ushort)Tags.GameStartDataResponse, new GameStartData(playerSpawnData, VGS_RegionManager.Instance.region.serverTick)))
{
Client.SendMessage(m, SendMode.Reliable);
}
}