Esempio n. 1
0
        void ShowRaycast()
        {
            if (!ShowPlayerRaycast)
            {
                return;
            }
            var pc = ClientPlayerEntityManager.Instance;

            if (pc == null)
            {
                return;
            }
            var localPlayer = pc.LocalPlayer;

            if (localPlayer == null)
            {
                return;
            }
            var view = localPlayer.View;

            if (view == null)
            {
                return;
            }
            var rawPos   = view.Interactor.CurrentOutPos;
            var floorPos = new Vector3(Mathf.Floor(rawPos.x), Mathf.Floor(rawPos.y), Mathf.Floor(rawPos.z)) + new Vector3(0.5f, 0.5f, 0.5f);

            Gizmos.DrawWireCube(floorPos, Vector3.one);
            Gizmos.color = Color.cyan;

            Gizmos.DrawRay(view.Interactor.transform.position, view.Interactor.ViewDirection * 15f);
            var result = VoxelsUtils.Cast(view.Interactor.transform.position, view.Interactor.ViewDirection, 15, (pos) => {
                var p = pos.ToVector3 + new Vector3(0.5f, 0.5f, 0.5f);
                Gizmos.DrawWireCube(p, Vector3.one);
                return(!ClientChunkManager.Instance.GetBlockIn(pos.X, pos.Y, pos.Z).IsEmpty());
            }, out var hit);

            if (!result)
            {
                return;
            }
            Gizmos.color = Color.yellow;
            var voxelPos = new Vector3(Mathf.Floor(hit.HitPosition.x), Mathf.Floor(hit.HitPosition.y), Mathf.Floor(hit.HitPosition.z));
            var outPos   = hit.Normal * 0.5f + voxelPos;

            Gizmos.DrawWireCube(new Vector3(Mathf.Floor(outPos.x), Mathf.Floor(outPos.y), Mathf.Floor(outPos.z)) + new Vector3(0.5f, 0.5f, 0.5f), Vector3.one);
            Gizmos.DrawWireSphere(hit.HitPosition, 0.2f);
            Gizmos.DrawRay(hit.HitPosition, hit.Normal * 0.5f);
        }
Esempio n. 2
0
        public bool GetBlockInSight(PlayerEntity player, out Vector3 blockPos, out BlockData block)
        {
            blockPos = Vector3.zero;
            block    = BlockData.Empty;
            if (player == null)
            {
                return(false);
            }
            var lookDir = GetPlayerLookDirection(player);

            if (VoxelsUtils.Cast(player.Position + Vector3.up * 0.5f, lookDir, PlayerInteraction.MAX_SIGHT_DISTANCE, VoxelsUtilsServerside.HasAnyBlock, out var result))
            {
                blockPos = result.HitPosition + lookDir * 0.03f;
                block    = ServerChunkManager.Instance.GetBlockIn(blockPos);
                return(true);
            }
            return(false);
        }
Esempio n. 3
0
        bool CheckHorizontalPoints(Vector3 direcion, float distance, out float minDistance)
        {
            var bottomCheckPos = Position + new Vector3(0, -DownHeight + Radius, 0);
            var upCheckPos     = Position + new Vector3(0, UpHeight - Radius, 0);

            minDistance = 0f;
            var a = VoxelsUtils.Cast(bottomCheckPos, direcion, distance, IsBlockSolid, out var bottomCastResult);
            var b = VoxelsUtils.Cast(upCheckPos, direcion, distance, IsBlockSolid, out var upCastResult);

            if (a || b)
            {
                var upD = Vector3.Distance(upCheckPos, upCastResult.HitPosition);
                var dnD = Vector3.Distance(bottomCheckPos, bottomCastResult.HitPosition);
                minDistance = Mathf.Min(upD, dnD);
                return(true);
            }
            return(false);
        }
        void ShowRaycast()
        {
            if (!ShowPlayerRaycast)
            {
                return;
            }
            var pc = ClientPlayerEntityManager.Instance;

            if (pc == null)
            {
                return;
            }
            var localPlayer = pc.LocalPlayer;

            if (localPlayer == null)
            {
                return;
            }
            var view = localPlayer.View;

            if (view == null)
            {
                return;
            }
            var rawPos   = view.Interactor.CurrentOutPos;
            var floorPos = new Vector3(Mathf.Floor(rawPos.x), Mathf.Floor(rawPos.y), Mathf.Floor(rawPos.z)) + new Vector3(0.5f, 0.5f, 0.5f);

            Gizmos.DrawWireCube(floorPos, Vector3.one);
            Gizmos.color = Color.cyan;

            Gizmos.DrawRay(view.Interactor.transform.position, view.Interactor.ViewDirection * 15f);
            var result = VoxelsUtils.Cast(view.Interactor.transform.position, view.Interactor.ViewDirection, 15, (pos) => {
                var p = pos.ToVector3 + new Vector3(0.5f, 0.5f, 0.5f);
                Gizmos.DrawWireCube(p, Vector3.one);
                var result = ClientChunkManager.Instance.GetBlockIn(pos.X, pos.Y, pos.Z).IsEmpty();
                if (!result)
                {
                    var ray      = new Voxels.Utils.Collisions.Ray(view.Interactor.transform.position, view.Interactor.ViewDirection.normalized);
                    var size     = new Vector3(1, 0.5f, 1);
                    var center   = new Vector3(0.5f, 0.25f, 0.5f);
                    var voxPos   = new Vector3(pos.X, pos.Y, pos.Z);
                    var checkCen = center + voxPos;
                    var cube     = new AABB(checkCen + size * 0.5f, checkCen - size * 0.5f);
                    Gizmos.DrawWireCube(cube.Center, size);
                    if (Intersection.Intersects(ray, cube, out var dist))
                    {
                        Gizmos.color = Color.red;
                        var colPoint = ray.Point + ray.Dir.normalized * dist;
                        Gizmos.DrawWireSphere(colPoint, 0.1f);
                    }


                    Gizmos.DrawCube(cube.Center, size);
                }
                return(!result);
            }, out var hit);

            if (!result)
            {
                return;
            }
            Gizmos.color = Color.yellow;
            var voxelPos = new Vector3(Mathf.Floor(hit.HitPosition.x), Mathf.Floor(hit.HitPosition.y), Mathf.Floor(hit.HitPosition.z));
            var outPos   = hit.Normal * 0.5f + voxelPos;

            Gizmos.DrawWireCube(new Vector3(Mathf.Floor(outPos.x), Mathf.Floor(outPos.y), Mathf.Floor(outPos.z)) + new Vector3(0.5f, 0.5f, 0.5f), Vector3.one);
            Gizmos.DrawWireSphere(hit.HitPosition, 0.2f);
            Gizmos.DrawRay(hit.HitPosition, hit.Normal * 0.5f);
        }