Beispiel #1
0
        public float checkRaysTop(IGravityClient gameObject, float yAangle, float zAngle, int layersToIgnore = 0)
        {
            RaycastHit2D hitLeftTop;
            RaycastHit2D hitMiddleTop;
            RaycastHit2D hitRightTop;

            float distanceTop = checkRay(gameObject, posRayLeftTop,
                                         1000.0f, yAangle, zAngle, out hitLeftTop, Color.red, layersToIgnore);
            float tmpDistanceTop = checkRay(gameObject, posRayMiddleTop,
                                            1000.0f, yAangle, zAngle, out hitMiddleTop, Color.red, layersToIgnore);

            distanceTop = (distanceTop < tmpDistanceTop) ? distanceTop : tmpDistanceTop;

            tmpDistanceTop = checkRay(gameObject, posRayRightTop,
                                      1000.0f, yAangle, zAngle, out hitRightTop, Color.red, layersToIgnore);

            distanceTop = (distanceTop < tmpDistanceTop) ? distanceTop : tmpDistanceTop;

            RayHitboxes rayHitboxes = gameObject.getRayHitboxes();

            rayHitboxes.HitLeftTop   = hitLeftTop;
            rayHitboxes.HitMiddleTop = hitMiddleTop;
            rayHitboxes.HitRightTop  = hitRightTop;
            rayHitboxes.DistanceTop  = distanceTop;
            gameObject.setRayHitboxes(rayHitboxes);

            return(distanceTop);
        }
Beispiel #2
0
        public virtual bool checkObjectHitsFloor(IGravityClient object_)
        {
#if USE_3D_RAYS
            RayInformation3D rayInformation = object_.getRayInformation3D();
            RayHitboxes3D    rayHitboxes    = object_.getRayHitboxes3D();
#else
            RayInformation rayInformation = object_.getRayInformation();
            RayHitboxes    rayHitboxes    = object_.getRayHitboxes();
#endif
            rayInformation.checkRaysBelow(object_, 0.0f,
                                          object_.getTransform().eulerAngles.z + 270.0f,
                                          layermask);
            float correction = 0.0f;
            float minimalSpaceBetweenTileBelow = rayInformation.MinimalSpaceBetweenTileBelow;

            bool objectOnFloor = (rayHitboxes.DistanceBelow <
                                  minimalSpaceBetweenTileBelow * rayInformation.BelowTolerance) ? true :
                                 ((multiplyYVelocityDown * yFallDistance) > (rayHitboxes.DistanceBelow -
                                                                             minimalSpaceBetweenTileBelow)) ? true : false;

            if (objectOnFloor)
            {
                correction = -(rayHitboxes.DistanceBelow -
                               rayInformation.MinimalSpaceBetweenTileBelow);
                moveEntity(object_, correction);
            }

            return(objectOnFloor);
        }
Beispiel #3
0
        public void setRayHitboxes(RayHitboxes rayHitboxes)
        {
#if USE_3D_RAYS
#else
            actor.RayHitboxes = rayHitboxes;
#endif
        }
Beispiel #4
0
        public float checkRaysFront(IGravityClient gameObject, float yAangle, float zAngle, int layerMask = 0, bool ignoreSlope = false)
        {
            RaycastHit2D hitTopFront;
            RaycastHit2D hitMiddleFront;
            RaycastHit2D hitBelowFront;

            float distance = (gameObject.isFlipped()) ? -1000.0f : 1000.0f;

            float distanceFront = (!gameObject.isFlipped()) ? checkRay(gameObject, posRayTopFront,
                                                                       distance, yAangle, zAngle, out hitTopFront, Color.green, layerMask + ((ignoreSlope)? 0 : (1 << slopeLayerNumber))) :
                                  checkRayFlipped(gameObject, posRayTopFront,
                                                  distance, yAangle, zAngle, out hitTopFront, Color.green, layerMask + ((ignoreSlope) ? 0 : (1 << slopeLayerNumber)));

            float tmpDistanceFront = (!gameObject.isFlipped()) ? checkRay(gameObject, posRayMiddleFront,
                                                                          distance, yAangle, zAngle, out hitMiddleFront, Color.green, layerMask + ((ignoreSlope) ? 0 : (1 << slopeLayerNumber))) :
                                     checkRayFlipped(gameObject, posRayMiddleFront,
                                                     distance, yAangle, zAngle, out hitMiddleFront, Color.green, layerMask + ((ignoreSlope) ? 0 : (1 << slopeLayerNumber)));

            distanceFront = (distanceFront < tmpDistanceFront) ? distanceFront : tmpDistanceFront;

            RayHitboxes rayHitboxes = gameObject.getRayHitboxes();

            if (rayHitboxes.HitMiddleFront.collider != null &&
                rayHitboxes.HitMiddleFront.collider.tag.CompareTo("Slope") != 0)
            {
                tmpDistanceFront = (!gameObject.isFlipped()) ? checkRay(gameObject, posRayBelowFront,
                                                                        distance, yAangle, zAngle, out hitBelowFront, Color.green, layerMask) :
                                   checkRayFlipped(gameObject, posRayBelowFront,
                                                   distance, yAangle, zAngle, out hitBelowFront, Color.green, layerMask);

                rayHitboxes.HitBelowFront = hitBelowFront;

                if (rayHitboxes.HitBelowFront.collider != null &&
                    rayHitboxes.HitBelowFront.collider.tag.CompareTo("Slope") != 0)
                {
                    distanceFront = (distanceFront < tmpDistanceFront) ? distanceFront : tmpDistanceFront;
                }
            }
            else
            {
                hitBelowFront             = new RaycastHit2D();
                hitBelowFront.distance    = -1.0f;
                rayHitboxes.HitBelowFront = hitBelowFront;
            }
            rayHitboxes.HitMiddleFront = hitMiddleFront;
            rayHitboxes.HitTopFront    = hitTopFront;
            rayHitboxes.DistanceFront  = distanceFront;
            gameObject.setRayHitboxes(rayHitboxes);

            return(distanceFront);
        }
Beispiel #5
0
        public float checkAttackRay(IGravityClient gameObject, Vector3 startPosRay, Vector3 endPosRay, string tag)
        {
            float        result          = -1.0f;
            RaycastHit2D attackRayResult = Physics2D.Raycast(startPosRay, endPosRay);

            if (attackRayResult.collider.tag.CompareTo(tag) == 0)
            {
                result = attackRayResult.distance;
            }

            RayHitboxes rayHitboxes = gameObject.getRayHitboxes();

            rayHitboxes.AttackRayResult = attackRayResult;
            gameObject.setRayHitboxes(rayHitboxes);

            return(result);
        }
Beispiel #6
0
        public float checkRaysBelow(IGravityClient gameObject, float yAangle, float zAngle, int layersToIgnore, bool doIgnoreSlope = true)
        {
            RaycastHit2D hitMiddleBelow;
            RaycastHit2D hitLeftBelow;
            RaycastHit2D hitRightBelow;

            float distanceBelow = checkRay(gameObject, posRayMiddleBelow,
                                           1000.0f, yAangle, zAngle, out hitMiddleBelow, Color.blue, layersToIgnore + (1 << slopeLayerNumber));

            float belowTolerance = ((hitMiddleBelow.collider.tag.CompareTo("Slope") == 0) ? this.belowTolerance : 1.0f);

            bool rightRayOnSlope = checkRightRayBelowForSlope(gameObject, yAangle, zAngle, out hitRightBelow, layersToIgnore);
            bool leftRayOnSlope  = checkLeftRayBelowForSlope(gameObject, yAangle, zAngle, out hitLeftBelow, layersToIgnore);

            float leftDistanceBelow = checkRay(gameObject, posRayLeftBelow, 1000.0f, yAangle,
                                               zAngle, out hitLeftBelow, Color.gray, layersToIgnore + ((doIgnoreSlope) ? 0 : (1 << slopeLayerNumber)));

            float rightDistanceBelow = checkRay(gameObject, posRayRightBelow, 1000.0f, yAangle,
                                                zAngle, out hitRightBelow, Color.green, layersToIgnore + ((doIgnoreSlope) ? 0 : (1 << slopeLayerNumber)));

            if (!doIgnoreSlope ||
                (doIgnoreSlope && distanceBelow >= (minimalSpaceBetweenTileBelow * belowTolerance)))
            {
                if (leftDistanceBelow < distanceBelow)
                {
                    distanceBelow = leftDistanceBelow;
                }
                if (distanceBelow > rightDistanceBelow)
                {
                    distanceBelow = rightDistanceBelow;
                }
            }

            RayHitboxes rayHitboxes = gameObject.getRayHitboxes();

            rayHitboxes.HitMiddleBelow = hitMiddleBelow;
            rayHitboxes.HitLeftBelow   = hitLeftBelow;
            rayHitboxes.HitRightBelow  = hitRightBelow;
            rayHitboxes.DistanceBelow  = distanceBelow;
            gameObject.setRayHitboxes(rayHitboxes);

            return(distanceBelow);
        }
Beispiel #7
0
        public virtual bool checkObjectHitsPlatform(float yModifier, IGravityClient object_)
        {
#if USE_3D_RAYS
            RayInformation3D rayInformation = object_.getRayInformation3D();
            RayHitboxes3D    rayHitboxes    = object_.getRayHitboxes3D();
#else
            RayInformation rayInformation = object_.getRayInformation();
            RayHitboxes    rayHitboxes    = object_.getRayHitboxes();
#endif
            rayInformation.checkRaysTop(object_, 0.0f, object_.getTransform().eulerAngles.z + 90.0f, layermask);
            bool objectHitTop = (rayHitboxes.DistanceTop <
                                 rayInformation.MinimalSpaceBetweenTileTop) ? true :
                                (yModifier > (rayHitboxes.DistanceTop -
                                              rayInformation.MinimalSpaceBetweenTileTop)) ? true : false;

            if (objectHitTop)
            {
                float correction = -(rayHitboxes.DistanceTop -
                                     rayInformation.MinimalSpaceBetweenTileTop);
                moveEntity(object_, correction);
                checkObjectHitsFloor(object_);
            }
            return(objectHitTop);
        }