示例#1
0
        private static bool IsHitGround(PlayerEntity playerEntity, float dist)
        {
            var        gameObject     = playerEntity.RootGo();
            var        prevLayer      = gameObject.layer;
            var        prev           = IntersectionDetectTool.SetColliderDisable(gameObject);
            var        playerPosition = gameObject.transform.position;
            var        playerRotation = gameObject.transform.rotation;
            var        controller     = playerEntity.characterContoller.Value;
            var        valueRadius    = playerEntity.characterContoller.Value.radius;
            var        isHit          = false;
            RaycastHit outHit;

            if (UseSphereCast(controller))
            {
                //use sphere cast
                var position = playerPosition + playerRotation * new Vector3(0f, valueRadius, 0f);

//            DebugDraw.DebugWireSphere(startPoint, Color.red, CastRadius, 1f);
//            DebugDraw.DebugWireSphere(startPoint + new Vector3(0,targetHeight - CastRadius - LiftUp,0), Color.magenta, CastRadius, 1f);
                isHit = PhysicsCastHelper.SphereCast(position, CastRadius, Vector3.down, out outHit, dist,
                                                     UnityLayers.AllCollidableLayerMask, QueryTriggerInteraction.Ignore, 0.1f);
                if (!isHit)
                {
                    //DebugDraw.DebugWireSphere(position + (isHit ? Vector3.down * outHit.distance : Vector3.down * dist),isHit ? Color.green : (playerEntity.characterContoller.Value.isGrounded ? Color.magenta : Color.red) ,CastRadius, isHit ? 0f:60f);
                }
            }
            else
            {
                Vector3 point1, point2;
                float   radius;
                var     height = controller.height;
                radius = controller.radius;
                var center = controller.center;
                PhysicsCastHelper.GetCapsule(controller.transform.position, controller.transform.rotation, height, radius, center, controller.direction, out point1, out point2);
                isHit = PhysicsCastHelper.CapsuleCast(point1, point2, radius, Vector3.down, out outHit, dist,
                                                      UnityLayers.AllCollidableLayerMask, QueryTriggerInteraction.Ignore, 0.1f);
                if (!isHit && false)
                {
                    PhysicsCastHelper.GetDebugDrawTypeCapsule(controller.transform.position, controller.transform.rotation, height, radius, center, controller.direction, out point1, out point2);
                    DebugDraw.DebugCapsule(point1 + (isHit ? Vector3.down * outHit.distance : Vector3.down * dist),
                                           point2 + (isHit ? Vector3.down * outHit.distance : Vector3.down * dist),
                                           isHit ? Color.green : (playerEntity.characterContoller.Value.isGrounded ? Color.magenta : Color.red),
                                           radius,
                                           isHit ? 0f:60f
                                           );
                }
            }


            IntersectionDetectTool.RestoreCollider(gameObject, prev);
            return(isHit);
        }
        private static bool IsHitGround(PlayerEntity playerEntity, float dist)
        {
            var gameObject = playerEntity.RootGo();
            var prevLayer  = gameObject.layer;

            IntersectionDetectTool.SetColliderDisable(gameObject, IntersectionDetectTool.ColliderEnableState);
            var        playerPosition = gameObject.transform.position;
            var        playerRotation = gameObject.transform.rotation;
            var        controller     = playerEntity.characterContoller.Value;
            var        valueRadius    = playerEntity.characterContoller.Value.radius;
            var        isHit          = false;
            RaycastHit outHit;

            if (UseSphereCast(controller))
            {
                //use sphere cast
                var position = playerPosition + playerRotation * new Vector3(0f, valueRadius, 0f);

                isHit = PhysicsCastHelper.SphereCast(position, CastRadius, Vector3.down, out outHit, dist,
                                                     UnityLayers.AllCollidableLayerMask, QueryTriggerInteraction.Ignore, 0.1f);
            }
            else
            {
                Vector3 point1, point2;
                float   radius;
                var     height = controller.height;
                radius = controller.radius;
                var center = controller.center;
                PhysicsCastHelper.GetCapsule(controller.transform.position, controller.transform.rotation, height, radius, center, controller.direction, out point1, out point2);
                isHit = PhysicsCastHelper.CapsuleCast(point1, point2, radius, Vector3.down, out outHit, dist,
                                                      UnityLayers.AllCollidableLayerMask, QueryTriggerInteraction.Ignore, 0.1f);
            }


            IntersectionDetectTool.RestoreCollider(gameObject, IntersectionDetectTool.ColliderEnableState);
            return(isHit);
        }