Пример #1
0
        /// <summary>
        /// Initialize Ground Detection
        /// </summary>
        /// <param name="bodyData">BodyData of the character.</param>
        /// <param name="maxDetectCount">Capacity of the BoxCast hit result array.</param>
        /// <param name="snapLength">If the character and ground are closer than or equal to snapLength, character will snap to the ground.</param>
        /// <param name="innerGap">BoxCollider's size.y will shrink. (Increase this if the character acts weird on slope.)</param>
        public void Init(
            BPCC_BodyData bodyData,
            int maxDetectCount,
            float snapLength,
            float innerGap)
        {
            this.bodyData       = bodyData;
            this.maxDetectCount = Mathf.Max(maxDetectCount, 0);
            this.snapLength     = Mathf.Max(snapLength, 0);
            this.innerGap       = Mathf.Max(innerGap, 0);

            groundLayer = LayerMaskHelper.Create(solidLayer, oneWayLayer);
            hitArray    = new RaycastHit2D[maxDetectCount];

            ApplyInnerGap();
        }
Пример #2
0
        /// <summary>
        /// Initialize Ground Detection
        /// </summary>
        /// <param name="bodyData">BodyData of the character.</param>
        /// <param name="maxDetectCount">Capacity of the BoxCast hit result array.</param>
        /// <param name="maxWalkAngle">If a ground angle is bigger than maxWalkAngle, character will slide down.</param>
        /// <param name="snapLength">If the character and ground are closer than or equal to snapLength, character will snap to the ground.</param>
        /// <param name="innerGap">BoxCollider's size.y will shrink. (Increase this if the character acts weird on slope.)</param>
        public void Init(
            BPCC_BodyData bodyData,
            int maxDetectCount,
            float maxWalkAngle,
            float snapLength,
            float innerGap)
        {
            this.bodyData       = bodyData;
            this.maxDetectCount = Mathf.Max(maxDetectCount, 0);
            this.maxWalkAngle   = Mathf.Clamp(maxWalkAngle, 0, 89);
            this.snapLength     = Mathf.Max(snapLength, 0);
            this.innerGap       = Mathf.Max(innerGap, 0);

            contactOffset = Physics2D.defaultContactOffset;
            prevPos       = bodyData.transform.position;
            groundLayer   = LayerMaskHelper.Create(solidLayer, oneWayLayer);
            hitArray      = new RaycastHit2D[maxDetectCount];

            ApplyInnerGap();

            // TODO:
            // Set up one way collider surface arc
            // depending on maxWalkAngle
        }