Example #1
0
        private bool CastLeft(ref Vector3 origin, ref Vector2 deltaMovement)
        {
            float distance = Mathf.Abs(deltaMovement.x) + this._skinWidth + 0.001f;
            float x        = deltaMovement.x;

            this._boxCaster.leftRaycaster.caster.contactFilter.SetLayerMask(this.terrainMask);
            this._boxCaster.leftRaycaster.caster.origin   = origin;
            this._boxCaster.leftRaycaster.caster.distance = distance;
            this._boxCaster.leftRaycaster.Cast();
            using (this.collisionState.leftCollisionDetector.scope) {
                for (int i = 0; i < this._boxCaster.leftRaycaster.nonAllocCasters.Count; i++)
                {
                    NonAllocCaster nonAllocCaster = this._boxCaster.leftRaycaster.nonAllocCasters[i];
                    if (nonAllocCaster.results.Count != 0)
                    {
                        RaycastHit2D hit = nonAllocCaster.results[0];
                        if (hit)
                        {
                            if (hit.distance == 0f)
                            {
                                return(false);
                            }

                            x = Mathf.Max(deltaMovement.x, -hit.distance + this._skinWidth);
                            this.collisionState.leftCollisionDetector.Add(hit);
                        }
                    }
                }
            }

            deltaMovement.x = x;
            return(true);
        }
Example #2
0
        private bool CastDown(ref Vector3 origin, ref Vector2 deltaMovement)
        {
            float distance = Mathf.Abs(deltaMovement.y) + this._skinWidth + 0.001f;

            if (this.ignorePlatform)
            {
                this._boxCaster.bottomRaycaster.caster.contactFilter.SetLayerMask(this.terrainMask);
            }
            else
            {
                this._boxCaster.bottomRaycaster.caster.contactFilter.SetLayerMask(
                    this.terrainMask | this.oneWayPlatformMask);
            }

            this._boxCaster.bottomRaycaster.caster.origin   = origin;
            this._boxCaster.bottomRaycaster.caster.distance = distance;
            this._boxCaster.bottomRaycaster.Cast();
            using (this.collisionState.belowCollisionDetector.scope) {
                for (int i = 0; i < this._boxCaster.bottomRaycaster.nonAllocCasters.Count; i++)
                {
                    NonAllocCaster nonAllocCaster = this._boxCaster.bottomRaycaster.nonAllocCasters[i];
                    if (nonAllocCaster.results.Count != 0)
                    {
                        RaycastHit2D hit = nonAllocCaster.results[0];
                        if (hit)
                        {
                            if (hit.distance == 0f)
                            {
                                return(false);
                            }

                            deltaMovement.y = Mathf.Max(deltaMovement.y, -hit.distance + this._skinWidth);
                            this.collisionState.lastStandingCollider = hit.collider;
                            this.collisionState.belowCollisionDetector.Add(hit);
                        }
                    }
                }
            }

            return(true);
        }