// TODO Future, Do raycast on server instead of client side public void Interact(Vector3Int point, bool leftClick) { if ((head.position - point).sqrMagnitude > Settings.DigDistance * Settings.DigDistance) { Debug.Log("To far away to Interact"); return; } if (leftClick) { Vector3 pos = point + new Vector3(0.5f + UnityEngine.Random.Range(0, 0.1f), 0.15f, 0.5f + UnityEngine.Random.Range(0, 0.1f)); DroppedBlock.Instantiate(World.Get.GetBlock(point.x, point.y, point.z), pos); World.Get.Interact(point.x, point.y, point.z, BlockType.Air); } else { World.Get.SetBlock(point.x, point.y, point.z, inventory.HeldBlock); if (PlayerCollider.AnyCollision()) { World.Get.SetBlock(point.x, point.y, point.z, BlockType.Air); } else { World.Get.Interact(point.x, point.y, point.z, inventory.HeldBlock); } } }
void UpdateWalking(Vector2 inputDirection) { if (isSwimming) { yVel += gravity / 2f; } else { yVel += gravity; } if (isGrounded && inputs[5]) { yVel = jumpForce; } if (isSwimming && inputs[5]) { yVel += swimmForce; } Vector3 updateVel = (transform.right * inputDirection.x + transform.forward * inputDirection.y * (inputs[6] ? 1.5f : 1f)) * speed; updateVel += new Vector3(0f, yVel, 0f); isSwimming = false; transform.position += new Vector3(0, updateVel.y, 0); if (PlayerCollider.Collision(transform, out isGrounded, out bool swimming)) { transform.position -= new Vector3(0, updateVel.y, 0); yVel = -2f * Time.fixedDeltaTime; } isSwimming |= swimming; transform.position += new Vector3(updateVel.x, 0, 0); if (PlayerCollider.Collision(transform, out bool _, out swimming)) { transform.position -= new Vector3(updateVel.x, 0, 0); } isSwimming |= swimming; transform.position += new Vector3(0, 0, updateVel.z); if (PlayerCollider.Collision(transform, out bool _, out swimming)) { transform.position -= new Vector3(0, 0, updateVel.z); } isSwimming |= swimming; }