sync player spawning
This commit is contained in:
@@ -145,6 +145,11 @@ public class Client
|
||||
|
||||
world.EditBlock(chunk, positionInChunk, blockID);
|
||||
}
|
||||
|
||||
if (data[0] == 5)
|
||||
{
|
||||
world.AddPlayer(data[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@ public class Player : MonoBehaviour
|
||||
client = world.GetClient();
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
camera = GetComponentInChildren<Camera>();
|
||||
transform.position = new Vector3((byte)transform.position.x,
|
||||
world.GetHeight((byte)transform.position.x, (byte)transform.position.z) + 2, (byte)transform.position.z);
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
|
||||
@@ -7,11 +7,12 @@ public class World : MonoBehaviour
|
||||
{
|
||||
//basic
|
||||
[SerializeField] private Material material;
|
||||
[SerializeField] private GameObject playerPrefab;
|
||||
public int worldSize;
|
||||
private string name;
|
||||
private string ip;
|
||||
private int port;
|
||||
|
||||
private Dictionary<byte, GameObject> otherPlayers = new Dictionary<byte, GameObject>();
|
||||
private Queue<byte> playersToCreate = new Queue<byte>();
|
||||
|
||||
//chunks
|
||||
private Chunk[,] chunks;
|
||||
private Queue<ChunkCoord> chunksToUpdate = new Queue<ChunkCoord>();
|
||||
@@ -21,6 +22,8 @@ public class World : MonoBehaviour
|
||||
|
||||
//network
|
||||
private Client client;
|
||||
private string ip;
|
||||
private int port;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
@@ -37,6 +40,21 @@ public class World : MonoBehaviour
|
||||
ChunkCoord chunk = chunksToUpdate.Dequeue();
|
||||
chunks[chunk.x, chunk.z].Update();
|
||||
}
|
||||
|
||||
if (playersToCreate.Count > 0)
|
||||
{
|
||||
byte id = playersToCreate.Dequeue();
|
||||
GameObject player = Instantiate(playerPrefab);
|
||||
player.transform.position = new Vector3((byte)player.transform.position.x,
|
||||
GetHeight((byte)player.transform.position.x, (byte)player.transform.position.z) + 2, (byte)player.transform.position.z);
|
||||
player.transform.SetParent(gameObject.transform);
|
||||
otherPlayers.Add(id, player);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddPlayer(byte id)
|
||||
{
|
||||
playersToCreate.Enqueue(id);
|
||||
}
|
||||
|
||||
public void CreateChunkArray()
|
||||
@@ -143,7 +161,7 @@ public class World : MonoBehaviour
|
||||
return blockData[blockID].textures;
|
||||
}
|
||||
|
||||
private byte GetHeight(int x, int z)
|
||||
public byte GetHeight(int x, int z)
|
||||
{
|
||||
float scale = 0.025f;
|
||||
byte perlinHeight = 10;
|
||||
|
||||
Reference in New Issue
Block a user