Fix Player
Destroying block when resuming game from pause menu, Player "flying over ground" after falling down a block
This commit is contained in:
@@ -1808,7 +1808,7 @@ Transform:
|
|||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 1789911866}
|
m_GameObject: {fileID: 1789911866}
|
||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
m_LocalPosition: {x: 150, y: 50.039, z: 150}
|
m_LocalPosition: {x: 150, y: 49.961, z: 150}
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
m_Children:
|
m_Children:
|
||||||
- {fileID: 1934992309}
|
- {fileID: 1934992309}
|
||||||
@@ -1951,7 +1951,7 @@ Transform:
|
|||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 1934992308}
|
m_GameObject: {fileID: 1934992308}
|
||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
m_LocalPosition: {x: 0, y: 1.7, z: 0.036}
|
m_LocalPosition: {x: 0, y: 1.557, z: 0.036}
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
m_Children: []
|
m_Children: []
|
||||||
m_Father: {fileID: 1789911868}
|
m_Father: {fileID: 1789911868}
|
||||||
|
|||||||
@@ -67,6 +67,12 @@ public class Player : MonoBehaviour
|
|||||||
CalculateVelocity();
|
CalculateVelocity();
|
||||||
transform.Translate(velocity, Space.World);
|
transform.Translate(velocity, Space.World);
|
||||||
|
|
||||||
|
//fix error in calculated position y
|
||||||
|
if (isGrounded)
|
||||||
|
{
|
||||||
|
transform.position = new Vector3(transform.position.x, (int)transform.position.y, transform.position.z);
|
||||||
|
}
|
||||||
|
|
||||||
//check if position or rotation had changed and send an update
|
//check if position or rotation had changed and send an update
|
||||||
Vector3 position = transform.position;
|
Vector3 position = transform.position;
|
||||||
Quaternion rotation = transform.rotation;
|
Quaternion rotation = transform.rotation;
|
||||||
@@ -130,12 +136,15 @@ public class Player : MonoBehaviour
|
|||||||
transform.Rotate(0, mouseX * Time.timeScale, 0);
|
transform.Rotate(0, mouseX * Time.timeScale, 0);
|
||||||
|
|
||||||
//send destroy block request to server
|
//send destroy block request to server
|
||||||
if (Input.GetMouseButtonDown(0) || (Input.GetAxis("Right Trigger") > 0 && lastTriggerR == 0))
|
if(Time.timeScale > 0)
|
||||||
{
|
{
|
||||||
if (Physics.Raycast(camera.transform.position, camera.transform.forward, out RaycastHit hit, 8))
|
if (Input.GetMouseButtonDown(0) || (Input.GetAxis("Right Trigger") > 0 && lastTriggerR == 0))
|
||||||
{
|
{
|
||||||
hit.point += camera.transform.forward / 10;
|
if (Physics.Raycast(camera.transform.position, camera.transform.forward, out RaycastHit hit, 8))
|
||||||
client.EditBlock(hit.point, 0);
|
{
|
||||||
|
hit.point += camera.transform.forward / 10;
|
||||||
|
client.EditBlock(hit.point, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,12 +178,15 @@ public class Player : MonoBehaviour
|
|||||||
}
|
}
|
||||||
|
|
||||||
//send build block request to server
|
//send build block request to server
|
||||||
if (Input.GetMouseButtonDown(1) || (Input.GetAxis("Left Trigger") > 0 && lastTriggerL == 0))
|
if(Time.timeScale > 0)
|
||||||
{
|
{
|
||||||
if (Physics.Raycast(camera.transform.position, camera.transform.forward, out RaycastHit hit, 8))
|
if (Input.GetMouseButtonDown(1) || (Input.GetAxis("Left Trigger") > 0 && lastTriggerL == 0))
|
||||||
{
|
{
|
||||||
hit.point -= camera.transform.forward / 10;
|
if (Physics.Raycast(camera.transform.position, camera.transform.forward, out RaycastHit hit, 8))
|
||||||
client.EditBlock(hit.point, currentBlock);
|
{
|
||||||
|
hit.point -= camera.transform.forward / 10;
|
||||||
|
client.EditBlock(hit.point, currentBlock);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,10 +251,10 @@ public class Player : MonoBehaviour
|
|||||||
private float CheckDownSpeed(float downSpeed)
|
private float CheckDownSpeed(float downSpeed)
|
||||||
{
|
{
|
||||||
if (
|
if (
|
||||||
world.CheckBlock(new Vector3(transform.position.x - playerWidth, transform.position.y + downSpeed, transform.position.z - playerWidth)) ||
|
world.CheckBlock(new Vector3(transform.position.x - playerWidth, (int)(transform.position.y + downSpeed), transform.position.z - playerWidth)) ||
|
||||||
world.CheckBlock(new Vector3(transform.position.x + playerWidth, transform.position.y + downSpeed, transform.position.z - playerWidth)) ||
|
world.CheckBlock(new Vector3(transform.position.x + playerWidth, (int)(transform.position.y + downSpeed), transform.position.z - playerWidth)) ||
|
||||||
world.CheckBlock(new Vector3(transform.position.x + playerWidth, transform.position.y + downSpeed, transform.position.z + playerWidth)) ||
|
world.CheckBlock(new Vector3(transform.position.x + playerWidth, (int)(transform.position.y + downSpeed), transform.position.z + playerWidth)) ||
|
||||||
world.CheckBlock(new Vector3(transform.position.x - playerWidth, transform.position.y + downSpeed, transform.position.z + playerWidth))
|
world.CheckBlock(new Vector3(transform.position.x - playerWidth, (int)(transform.position.y + downSpeed), transform.position.z + playerWidth))
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
isGrounded = true;
|
isGrounded = true;
|
||||||
|
|||||||
@@ -66,9 +66,9 @@ public class World : MonoBehaviour
|
|||||||
{
|
{
|
||||||
byte id = playersToCreate.Dequeue();
|
byte id = playersToCreate.Dequeue();
|
||||||
GameObject player = Instantiate(playerPrefab);
|
GameObject player = Instantiate(playerPrefab);
|
||||||
player.transform.position = new Vector3((byte)player.transform.position.x,
|
player.transform.position = new Vector3((int)player.transform.position.x,
|
||||||
GetHeight((byte)player.transform.position.x, (byte)player.transform.position.z) + 2,
|
GetHeight((byte)player.transform.position.x, (byte)player.transform.position.z) + 2,
|
||||||
(byte)player.transform.position.z);
|
(int)player.transform.position.z);
|
||||||
player.transform.SetParent(gameObject.transform);
|
player.transform.SetParent(gameObject.transform);
|
||||||
otherPlayers.Add(id, player);
|
otherPlayers.Add(id, player);
|
||||||
}
|
}
|
||||||
@@ -174,7 +174,7 @@ public class World : MonoBehaviour
|
|||||||
(int)(positionInWorld.z / Data.chunkWidth));
|
(int)(positionInWorld.z / Data.chunkWidth));
|
||||||
|
|
||||||
int xInChunk = (int)(positionInWorld.x - chunk.x * Data.chunkWidth);
|
int xInChunk = (int)(positionInWorld.x - chunk.x * Data.chunkWidth);
|
||||||
int yInChunk = (int)positionInWorld.y;
|
int yInChunk = (int)(positionInWorld.y);
|
||||||
int zInChunk = (int)(positionInWorld.z - chunk.z * Data.chunkWidth);
|
int zInChunk = (int)(positionInWorld.z - chunk.z * Data.chunkWidth);
|
||||||
|
|
||||||
if (chunks[chunk.x, chunk.z] != null)
|
if (chunks[chunk.x, chunk.z] != null)
|
||||||
|
|||||||
Reference in New Issue
Block a user