Bug Fixing
Es können keine blöcke mehr "in" einen selbst oder in andere spieler gebaut werden
This commit is contained in:
@@ -32,7 +32,7 @@ TextureImporter:
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: 1
|
||||
filterMode: 0
|
||||
aniso: 1
|
||||
mipBias: 0
|
||||
wrapU: 0
|
||||
@@ -75,6 +75,18 @@ TextureImporter:
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Standalone
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
|
||||
@@ -184,11 +184,13 @@ public class Client
|
||||
world.EditBlock(chunk, positionInChunk, blockID);
|
||||
}
|
||||
|
||||
//add a new player
|
||||
if (data[0] == 5)
|
||||
{
|
||||
world.AddPlayer(data[1]);
|
||||
}
|
||||
|
||||
//update a players position
|
||||
if (data[0] == 7)
|
||||
{
|
||||
byte[] positionASCII = new byte[data.Length - 2];
|
||||
@@ -207,11 +209,13 @@ public class Client
|
||||
world.UpdatePlayerPosition(new Vector3(x, y, z), id);
|
||||
}
|
||||
|
||||
//remove a player from local world
|
||||
if (data[0] == 4)
|
||||
{
|
||||
world.RemovePlayer(data[1]);
|
||||
}
|
||||
|
||||
//update a players rotation
|
||||
if (data[0] == 8)
|
||||
{
|
||||
byte[] rotationASCII = new byte[data.Length - 2];
|
||||
@@ -234,6 +238,7 @@ public class Client
|
||||
|
||||
}
|
||||
|
||||
//sends an edit block request to server
|
||||
public void EditBlock(Vector3 positionInWorld, byte blockID)
|
||||
{
|
||||
ChunkCoord chunk = new ChunkCoord((int)(positionInWorld.x / Data.chunkWidth),
|
||||
@@ -247,6 +252,7 @@ public class Client
|
||||
Send(new byte[] { 3, (byte)chunk.x, (byte)chunk.z, xInChunk, yInChunk, zInChunk, blockID });
|
||||
}
|
||||
|
||||
//default send method
|
||||
private void Send(byte[] data)
|
||||
{
|
||||
client.Send(data, data.Length);
|
||||
|
||||
@@ -33,6 +33,8 @@ public class Player : MonoBehaviour
|
||||
private void Start()
|
||||
{
|
||||
client = world.GetClient();
|
||||
|
||||
//lock the cursor
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
camera = GetComponentInChildren<Camera>();
|
||||
transform.position = new Vector3((byte)transform.position.x,
|
||||
@@ -41,6 +43,7 @@ public class Player : MonoBehaviour
|
||||
|
||||
private void Jump()
|
||||
{
|
||||
//add velocity up
|
||||
verticalMomentum = jumpForce;
|
||||
isGrounded = false;
|
||||
jumpRequest = false;
|
||||
@@ -48,6 +51,7 @@ public class Player : MonoBehaviour
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
//if space was pressed
|
||||
if (jumpRequest)
|
||||
{
|
||||
Jump();
|
||||
@@ -56,6 +60,7 @@ public class Player : MonoBehaviour
|
||||
CalculateVelocity();
|
||||
transform.Translate(velocity, Space.World);
|
||||
|
||||
//check if position or rotation had changed and send an update
|
||||
Vector3 position = transform.position;
|
||||
Quaternion rotation = transform.rotation;
|
||||
|
||||
@@ -76,6 +81,7 @@ public class Player : MonoBehaviour
|
||||
|
||||
private void Update()
|
||||
{
|
||||
//get the player input
|
||||
horizontal = Input.GetAxisRaw("Horizontal");
|
||||
vertical = Input.GetAxisRaw("Vertical");
|
||||
mouseX = Input.GetAxis("Mouse X");
|
||||
@@ -86,6 +92,7 @@ public class Player : MonoBehaviour
|
||||
jumpRequest = true;
|
||||
}
|
||||
|
||||
//get the camera up and down movement and clamp it
|
||||
rotX -= mouseY * 1.4f;
|
||||
rotX = Mathf.Clamp(rotX, -90, 90);
|
||||
|
||||
@@ -93,6 +100,7 @@ public class Player : MonoBehaviour
|
||||
|
||||
transform.Rotate(0, mouseX, 0);
|
||||
|
||||
//send destroy block request to server
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
if (Physics.Raycast(camera.transform.position, camera.transform.forward, out RaycastHit hit))
|
||||
@@ -102,6 +110,7 @@ public class Player : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
//send build block request to server
|
||||
if (Input.GetMouseButtonDown(1))
|
||||
{
|
||||
if (Physics.Raycast(camera.transform.position, camera.transform.forward, out RaycastHit hit))
|
||||
@@ -114,24 +123,29 @@ public class Player : MonoBehaviour
|
||||
|
||||
private void CalculateVelocity()
|
||||
{
|
||||
//check if player can accelerate any faster (there is a max speed)
|
||||
if (verticalMomentum > gravity)
|
||||
{
|
||||
verticalMomentum += Time.fixedDeltaTime * gravity;
|
||||
}
|
||||
|
||||
//add velocity for moving, falling and jumping
|
||||
velocity = ((transform.forward * vertical) + (transform.right * horizontal)) * Time.fixedDeltaTime * walkSpeed;
|
||||
velocity += Vector3.up * verticalMomentum * Time.fixedDeltaTime;
|
||||
|
||||
//check colliders on z axis
|
||||
if ((velocity.z > 0 && front) || (velocity.z < 0 && back))
|
||||
{
|
||||
velocity.z = 0;
|
||||
}
|
||||
|
||||
//check colliders on x axis
|
||||
if ((velocity.x > 0 && right) || (velocity.x < 0 && left))
|
||||
{
|
||||
velocity.x = 0;
|
||||
}
|
||||
|
||||
//check colliders on y axis
|
||||
if (velocity.y < 0)
|
||||
{
|
||||
velocity.y = CheckDownSpeed(velocity.y);
|
||||
@@ -146,6 +160,7 @@ public class Player : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
//check colliders for -y
|
||||
private float CheckDownSpeed(float downSpeed)
|
||||
{
|
||||
if (
|
||||
@@ -163,6 +178,7 @@ public class Player : MonoBehaviour
|
||||
return downSpeed;
|
||||
}
|
||||
|
||||
//check colliders for +y
|
||||
private float CheckUpSpeed(float upSpeed)
|
||||
{
|
||||
if (
|
||||
@@ -178,6 +194,7 @@ public class Player : MonoBehaviour
|
||||
return upSpeed;
|
||||
}
|
||||
|
||||
//check colliders for +z
|
||||
public bool front
|
||||
{
|
||||
get
|
||||
@@ -194,6 +211,7 @@ public class Player : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
//check colliders for -z
|
||||
public bool back
|
||||
{
|
||||
get
|
||||
@@ -210,6 +228,7 @@ public class Player : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
//check colliders for -x
|
||||
public bool left
|
||||
{
|
||||
get
|
||||
@@ -226,6 +245,7 @@ public class Player : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
//check colliders for +x
|
||||
public bool right
|
||||
{
|
||||
get
|
||||
@@ -242,6 +262,7 @@ public class Player : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
//stores update data for position and if a player should be removed from the world
|
||||
public class PlayerPositionUpdateData
|
||||
{
|
||||
public PlayerPositionUpdateData(byte id, Vector3 position, bool destroy)
|
||||
@@ -256,6 +277,7 @@ public class Player : MonoBehaviour
|
||||
public bool destroy;
|
||||
}
|
||||
|
||||
//stores update data for rotations
|
||||
public class PlayerRotationsUpdateData
|
||||
{
|
||||
public byte id;
|
||||
|
||||
@@ -31,12 +31,14 @@ public class World : MonoBehaviour
|
||||
|
||||
private void Start()
|
||||
{
|
||||
//get default information
|
||||
name = PlayerPrefs.GetString("userName");
|
||||
ip = PlayerPrefs.GetString("serverIP");
|
||||
port = int.Parse(PlayerPrefs.GetString("port"));
|
||||
client = new Client(ip, port, this, name);
|
||||
}
|
||||
|
||||
//removes a player from the game world
|
||||
public void RemovePlayer(byte id)
|
||||
{
|
||||
playersPositionsToUpdate.Enqueue(new Player.PlayerPositionUpdateData(id, Vector3.zero, true));
|
||||
@@ -44,12 +46,14 @@ public class World : MonoBehaviour
|
||||
|
||||
private void Update()
|
||||
{
|
||||
//update 1 chunk in list
|
||||
if (chunksToUpdate.Count > 0)
|
||||
{
|
||||
ChunkCoord chunk = chunksToUpdate.Dequeue();
|
||||
chunks[chunk.x, chunk.z].Update();
|
||||
}
|
||||
|
||||
//create 1 player in list
|
||||
if (playersToCreate.Count > 0)
|
||||
{
|
||||
byte id = playersToCreate.Dequeue();
|
||||
@@ -61,6 +65,7 @@ public class World : MonoBehaviour
|
||||
otherPlayers.Add(id, player);
|
||||
}
|
||||
|
||||
//update 1 player position in list
|
||||
if (playersPositionsToUpdate.Count > 0)
|
||||
{
|
||||
Player.PlayerPositionUpdateData data = playersPositionsToUpdate.Dequeue();
|
||||
@@ -76,6 +81,7 @@ public class World : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
//update 1 player rotation in list
|
||||
if (playersRotationsToUpdate.Count > 0)
|
||||
{
|
||||
Player.PlayerRotationsUpdateData data = playersRotationsToUpdate.Dequeue();
|
||||
@@ -87,32 +93,37 @@ public class World : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
//enqueue player position update to list
|
||||
public void UpdatePlayerPosition(Vector3 position, byte id)
|
||||
{
|
||||
playersPositionsToUpdate.Enqueue(new Player.PlayerPositionUpdateData(id, position, false));
|
||||
}
|
||||
|
||||
//enqueue player rotation update to list
|
||||
public void UpdatePlayerRotation(Quaternion rotation, byte id)
|
||||
{
|
||||
playersRotationsToUpdate.Enqueue(new Player.PlayerRotationsUpdateData(id, rotation));
|
||||
}
|
||||
|
||||
//enqueue player create data to list
|
||||
public void AddPlayer(byte id)
|
||||
{
|
||||
playersToCreate.Enqueue(id);
|
||||
}
|
||||
|
||||
//creates the array for chunk objects
|
||||
public void CreateChunkArray()
|
||||
{
|
||||
chunks = new Chunk[worldSize, worldSize];
|
||||
}
|
||||
|
||||
//initialized a chunk
|
||||
public void InitChunk(int x, int z, byte[,,] blocks)
|
||||
{
|
||||
chunks[x, z] = new Chunk(material, new ChunkCoord(x, z), this, blocks);
|
||||
}
|
||||
|
||||
//creates an array of chunks
|
||||
//initialized the chunk objects
|
||||
public void CreateChunks()
|
||||
{
|
||||
for (int x = 0; x < worldSize; x++)
|
||||
@@ -206,6 +217,7 @@ public class World : MonoBehaviour
|
||||
return blockData[blockID].textures;
|
||||
}
|
||||
|
||||
//get the perlin noise height
|
||||
public byte GetHeight(int x, int z)
|
||||
{
|
||||
float scale = 0.025f;
|
||||
@@ -216,6 +228,7 @@ public class World : MonoBehaviour
|
||||
return height;
|
||||
}
|
||||
|
||||
//edit a block in local chunk storage
|
||||
public void EditBlock(ChunkCoord chunk, Vector3 positionInChunk, byte blockID)
|
||||
{
|
||||
byte xInChunk = (byte)(positionInChunk.x);
|
||||
|
||||
Reference in New Issue
Block a user