コード例 #1
0
        public Vector2 TryToMove(Vector2 wantsToMoveAmount, Vector2 deltaPosition = default, MoveMode mode = MoveMode.HorizontalFirst)
        {
            Vector2 movedAmount = deltaPosition;

            foreach (MoveUnit moveUnit in mode.GetMoveUnits(wantsToMoveAmount))
            {
                if (!RaycastHelpers.IsValidDistance(moveUnit.distance))
                {
                    continue;
                }

                movedAmount[moveUnit.axis] = moveUnit.dir * TryToMove(moveUnit.distance, moveUnit.dir, deltaPosition);
            }
            return(movedAmount - deltaPosition);
        }
コード例 #2
0
        private float GetAllowedMovementAt_Obsolete(float distance, Direction4 direction, Vector2 deltaPosition = default)
        {
            if (!RaycastHelpers.IsValidDistance(distance))
            {
                return(0);
            }

            IEnumerable <CollisionMoveHit> raycasterHits = GetCollisionMoveHits(distance, direction, deltaPosition);
            float allowedDistance = distance;

            foreach (CollisionMoveHit raycasterHit in raycasterHits)
            {
                allowedDistance = collisionMoveController.GetAllowedMoveInto(raycasterHit, allowedDistance);
            }
            return(allowedDistance);
        }
コード例 #3
0
        private float GetAllowedMovementAt(float distance, Dir4 dir, Vector2 deltaPosition = default)
        {
            if (!RaycastHelpers.IsValidDistance(distance))
            {
                return(0);
            }

            (RaycastHit2D[] raycastHits, int count) = raycaster.GetHits(distance, dir, deltaPosition);
            IEnumerable <RaycastHit2D> uniqueHits = collisionMoveHitsFactory.GetUnique(raycastHits, count);
            float allowedDistance = distance;

            foreach (RaycastHit2D hit in uniqueHits)
            {
                allowedDistance = collisionMoveController.GetAllowedMoveInto(hit, allowedDistance, dir);
            }
            return(allowedDistance);
        }
コード例 #4
0
        private (bool, float) GetJumpCornerCorrectionFor(float topMovementAmount, DirX rayDirX)
        {
            Dir4         rayDir      = Dir4.FromXFloat(rayDirX);
            Bounds       bounds      = movement.boxCollider.bounds;
            float        rayLength   = jumpCornerCorrection;
            Vector2      upperCorner = BoundsHelpers.GetCorner(bounds, rayDirX, DirY.up);
            Vector2      rayDelta    = new Vector2(-rayDirX * rayLength, topMovementAmount);
            Vector2      rayOrigin   = upperCorner + rayDelta;
            RaycastHit2D cornerHit   = RaycastHelpers.SingleHit(rayOrigin, rayLength, rayDir, movement.layerMask);

            if (CanBeCornerCorrected(rayLength, rayDir, cornerHit))
            {
                float correctionValue = -rayDirX * (rayLength - cornerHit.distance);
                return(true, correctionValue);
            }
            return(false, 0);
        }
コード例 #5
0
        public float ForceMove(float distance, Direction4 direction)
        {
            if (!RaycastHelpers.IsValidDistance(distance))
            {
                return(NoDistanceForceMove(direction));
            }

            Vector2 origin = rigidbody.position;
            IEnumerable <CollisionMoveHit> raycasterHits = GetCollisionMoveHits(distance, direction);

            foreach (CollisionMoveHit raycasterHit in raycasterHits)
            {
                collisionMoveController.ForceMoveInto(raycasterHit, distance);
            }
            rigidbody.position = origin + direction.ToVector2(distance);

            return(distance);
        }
コード例 #6
0
        public (RaycastHit2D[], int) GetHits(Vector2 origin, float distance, Dir4 dir)
        {
            distance = RaycastHelpers.CeilDistance(distance);
            int rays             = rayDeltas.Length;
            int edgeRayHitsCount = 0;

            for (int i = 0; i < rays; i++)
            {
                Vector2 rayOrigin = origin + rayDeltas[i];
                (int singleRayHitsCount, RaycastHit2D[] singleRayHits) = RaycastHelpers.Raycast(rayOrigin, distance, dir, layerMask);
                if (edgeRayHitsCount + singleRayHitsCount > maxEdgeRayHitsCount)
                {
                    return(ForceReturnOverHitsResults(edgeRayHitsCount, singleRayHitsCount, singleRayHits));
                }
                Array.Copy(singleRayHits, 0, edgeRayHits, edgeRayHitsCount, singleRayHitsCount);
                edgeRayHitsCount += singleRayHitsCount;
            }

            return(edgeRayHits, edgeRayHitsCount);
        }
コード例 #7
0
        public float ForceMove(float distance, Dir4 dir)
        {
            if (!RaycastHelpers.IsValidDistance(distance))
            {
                return(NoDistanceForceMove(dir));
            }

            Vector2 origin = rigidbody.position;

            (RaycastHit2D[] raycastHits, int count) = raycaster.GetHits(distance, dir);
            IEnumerable <RaycastHit2D> uniqueHits = collisionMoveHitsFactory.GetUnique(raycastHits, count);

            foreach (RaycastHit2D hit in uniqueHits)
            {
                collisionMoveController.ForceMoveInto(hit, distance, dir);
            }

            Vector2 moveAmount = (Vector2)dir * distance;

            rigidbody.position = origin + moveAmount;

            return(distance);
        }