Beispiel #1
0
        public float checkRaysTop(IGravityClient gameObject, float yAangle, float zAngle, int layersToIgnore = 0)
        {
            RaycastHit hitLeftTop;
            RaycastHit hitMiddleTop;
            RaycastHit 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;

            RayHitboxes3D rayHitboxes = gameObject.getRayHitboxes3D();

            rayHitboxes.HitLeftTop   = hitLeftTop;
            rayHitboxes.HitMiddleTop = hitMiddleTop;
            rayHitboxes.HitRightTop  = hitRightTop;
            rayHitboxes.DistanceTop  = distanceTop;
            gameObject.setRayHitboxes3D(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 bool moveEntityDown(IEntity entity, KeysPressed keysPressed, Gravity gravity, float movementSpeed)
        {
            IGravityClient gravityClient = entity.getGravityClient();
            bool           moving        = false;

#if USE_3D_RAYS
            RayHitboxes3D rayHitboxes = gravityClient.getRayHitboxes3D();
#else
            RayHitboxes rayHitboxes = gravityClient.getRayHitboxes();
#endif
            Vector3 angles = new Vector3(entity.getTransform().eulerAngles.x,
                                         entity.getTransform().eulerAngles.y,
                                         entity.getTransform().eulerAngles.z);
#if USE_3D_RAYS
            RayInformation3D rayInformation = gravityClient.getRayInformation3D();
#else
            RayInformation rayInformation = gravityClient.getRayInformation();
#endif
            if (!keysPressed.up && keysPressed.down)
            {
                rayInformation.checkRaysBelow(gravityClient, 0.0f, angles.z + 270.0f, layermask);
            }
            bool  isWalking     = !entity.getGravity().isFalling() && !entity.getGravity().Jumping;
            float frontDistance = rayHitboxes.DistanceBelow;

            if (frontDistance > rayInformation.MinimalSpaceBetweenTileBelow)
            {
                if (!keysPressed.up && keysPressed.down)
                {
                    moving = true;

                    if (!entity.getRotateHorizontalMovement())
                    {
                        Vector3 pos = entity.getTransform().position;

                        if (angles.z > 90.0f && angles.z < 270.0f)
                        {
                            pos.y -= ((frontDistance - rayInformation.MinimalSpaceBetweenTileBelow) < movementSpeed * Time.fixedDeltaTime) ?
                                     (frontDistance - rayInformation.MinimalSpaceBetweenTileBelow) : movementSpeed * Time.fixedDeltaTime;
                        }
                        else
                        {
                            pos.y -= ((frontDistance - rayInformation.MinimalSpaceBetweenTileBelow) < movementSpeed * Time.fixedDeltaTime) ?
                                     (frontDistance - rayInformation.MinimalSpaceBetweenTileBelow) : movementSpeed * Time.fixedDeltaTime;
                        }
                        entity.getTransform().position = pos;
                    }

                    gravity.Reset = false;
                }
            }
            return(moving);
        }
Beispiel #4
0
        public float checkRaysFront(IGravityClient gameObject, float yAangle, float zAngle, int layersToIgnore = 0)
        {
            RaycastHit hitTopFront;
            RaycastHit hitMiddleFront;
            RaycastHit hitBelowFront;

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

            float distanceFront = (!gameObject.isFlipped()) ? checkRay(gameObject, posRayTopFront,
                                                                       distance, yAangle, zAngle, out hitTopFront, Color.green, layersToIgnore) :
                                  checkRayFlipped(gameObject, posRayTopFront,
                                                  distance, yAangle, zAngle, out hitTopFront, Color.green, layersToIgnore);

            float tmpDistanceFront = (!gameObject.isFlipped()) ? checkRay(gameObject, posRayMiddleFront,
                                                                          distance, yAangle, zAngle, out hitMiddleFront, Color.green, layersToIgnore) :
                                     checkRayFlipped(gameObject, posRayMiddleFront,
                                                     distance, yAangle, zAngle, out hitMiddleFront, Color.green, layersToIgnore);

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

            RayHitboxes3D rayHitboxes = gameObject.getRayHitboxes3D();

            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, layersToIgnore) :
                                   checkRayFlipped(gameObject, posRayBelowFront,
                                                   distance, yAangle, zAngle, out hitBelowFront, Color.green, layersToIgnore);

                rayHitboxes.HitBelowFront = hitBelowFront;

                if (rayHitboxes.HitBelowFront.collider != null &&
                    rayHitboxes.HitBelowFront.collider.tag.CompareTo("Slope") != 0)
                {
                    distanceFront = (distanceFront < tmpDistanceFront) ? distanceFront : tmpDistanceFront;
                }
            }
            rayHitboxes.HitMiddleFront = hitMiddleFront;
            rayHitboxes.HitTopFront    = hitTopFront;
            rayHitboxes.DistanceFront  = distanceFront;
            gameObject.setRayHitboxes3D(rayHitboxes);

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

            Physics.Raycast(startPosRay, endPosRay, out attackRayResult);
            if (attackRayResult.collider.tag.CompareTo(tag) == 0)
            {
                result = attackRayResult.distance;
            }

            RayHitboxes3D rayHitboxes = gameObject.getRayHitboxes3D();

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

            return(result);
        }
Beispiel #6
0
        public bool moveEntityUp(IEntity entity, KeysPressed keysPressed, Gravity gravity, float movementSpeed)
        {
            IGravityClient gravityClient = entity.getGravityClient();
            bool           moving        = false;

#if USE_3D_RAYS
            RayHitboxes3D rayHitboxes = gravityClient.getRayHitboxes3D();
#else
            RayHitboxes rayHitboxes = gravityClient.getRayHitboxes();
#endif
            Vector3 angles = new Vector3(entity.getTransform().eulerAngles.x,
                                         entity.getTransform().eulerAngles.y,
                                         entity.getTransform().eulerAngles.z);
#if USE_3D_RAYS
            RayInformation3D rayInformation = gravityClient.getRayInformation3D();
#else
            RayInformation rayInformation = gravityClient.getRayInformation();
#endif
            if (keysPressed.up && !keysPressed.down)
            {
                rayInformation.checkRaysTop(gravityClient, 0.0f, angles.z + 90.0f, layermask);
            }
            bool isWalking = !entity.getGravity().isFalling() && !entity.getGravity().Jumping;

            float frontDistance = rayHitboxes.DistanceTop;

            if (frontDistance > rayInformation.MinimalSpaceBetweenTileTop)
            {
                if (keysPressed.up && !keysPressed.down)
                {
                    moving = true;

                    Vector3 pos = entity.getTransform().position;

                    pos.y += ((frontDistance - rayInformation.MinimalSpaceBetweenTileTop) < movementSpeed * Time.fixedDeltaTime) ?
                             (frontDistance - rayInformation.MinimalSpaceBetweenTileTop) : movementSpeed * Time.fixedDeltaTime;

                    entity.getTransform().position = pos;

                    gravity.Reset = false;
                }
            }
            return(moving);
        }
Beispiel #7
0
        public float checkRaysBelow(IGravityClient gameObject, float yAangle, float zAngle, int layersToIgnore = 0)
        {
            RaycastHit hitMiddleBelow;
            RaycastHit hitLeftBelow;
            RaycastHit hitRightBelow;

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

            float leftDistanceBelow = checkRay(gameObject, posRayLeftBelow,
                                               1000.0f, yAangle, zAngle, out hitLeftBelow, Color.gray, layersToIgnore);

            float rightDistanceBelow = checkRay(gameObject, posRayRightBelow,
                                                1000.0f, yAangle, zAngle, out hitRightBelow, Color.blue, layersToIgnore);

            if (checkDistanceBetweenRays(hitLeftBelow, hitMiddleBelow))
            {
                distanceBelow = leftDistanceBelow;
            }
            if (leftDistanceBelow > rightDistanceBelow)
            {
                if (checkDistanceBetweenRays(hitRightBelow, hitMiddleBelow))
                {
                    distanceBelow = rightDistanceBelow;
                }
            }

            RayHitboxes3D rayHitboxes = gameObject.getRayHitboxes3D();

            rayHitboxes.HitMiddleBelow = hitMiddleBelow;
            rayHitboxes.HitLeftBelow   = hitLeftBelow;
            rayHitboxes.HitRightBelow  = hitRightBelow;
            rayHitboxes.DistanceBelow  = distanceBelow;
            gameObject.setRayHitboxes3D(rayHitboxes);
            return(distanceBelow);
        }
Beispiel #8
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);
        }