예제 #1
0
        public override void update(AICharacter character)
        {
            IGravityClient gravityClient  = character.getEntity().getGravityClient();
            KeysPressed    keysPressed    = character.getEntity().getKeysPressed();
            RayInformation rayInformation = character.getEntity().getGravityClient().getRayInformation();
            RayHitboxes    rayHitboxes    = gravityClient.getRayHitboxes();

            gravityClient.getRayInformation().checkRaysFront(gravityClient, 0.0f, character.getEntity().getTransform().eulerAngles.z + 0.0f, layermask, false);
            gravityClient.getRayInformation().checkRaysBelow(gravityClient, 0.0f, character.getEntity().getTransform().eulerAngles.z + 270.0f, layermask, false);

            float minimalSpaceBetweenTileBelow = rayInformation.MinimalSpaceBetweenTileBelow;
            float topFrontDistance             = (rayHitboxes.HitTopFront.distance * 0.9f);
            bool  turned = false;

            gravityClient.getRayInformation().checkRaysFront(gravityClient, 0.0f, character.getEntity().getTransform().eulerAngles.z + 0.0f, layermask, true);

            keysPressed = turnIfWallIsNear(gravityClient, topFrontDistance,
                                           rayInformation.MinimalSpaceBetweenTileFront, keysPressed, out turned);

            if (!turned && (rayHitboxes.HitMiddleBelow.collider.tag.CompareTo("Slope") != 0))
            {
                keysPressed = turnIfOnAnEdge(keysPressed, minimalSpaceBetweenTileBelow, character);
            }
            character.setKeysPressed(keysPressed);
        }
예제 #2
0
        private KeysPressed turnIfOnAnEdge(KeysPressed keysPressed,
                                           float minimalSpaceBetweenTileBelow, AICharacter character)
        {
            IGravityClient gravityClient = character.getEntity().getGravityClient();
            RayHitboxes    rayHitboxes   = gravityClient.getRayHitboxes();

            if (gravityClient.isFlipped() && rayHitboxes.HitLeftBelow.distance > 1.0f)
            {
                keysPressed.left  = false;
                keysPressed.right = true;
            }
            else if (gravityClient.isFlipped() &&
                     rayHitboxes.HitLeftBelow.distance <= minimalSpaceBetweenTileBelow)
            {
                keysPressed.left  = true;
                keysPressed.right = false;
            }

            if (!gravityClient.isFlipped() &&
                rayHitboxes.HitRightBelow.distance > 1.0f)
            {
                keysPressed.left  = true;
                keysPressed.right = false;
            }
            else if (!gravityClient.isFlipped() &&
                     rayHitboxes.HitRightBelow.distance <= minimalSpaceBetweenTileBelow)
            {
                keysPressed.left  = false;
                keysPressed.right = true;
            }

            return(keysPressed);
        }
예제 #3
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);
        }
예제 #4
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);
        }
예제 #5
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);
        }
예제 #6
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);
        }
예제 #7
0
파일: Move.cs 프로젝트: Thorig/LDJam44
        public override void update(IEntity entity)
        {
            Gravity        gravity       = entity.getGravity();
            KeysPressed    keysPressed   = entity.getKeysPressed();
            IGravityClient gravityClient = entity.getGravityClient();

#if USE_3D_RAYS
            gravityClient.getRayInformation3D().checkRaysFront(gravityClient, 0.0f, entity.getTransform().eulerAngles.z + 0.0f, entity.getGravityClient().getLayerToIgnore());
#else
            gravityClient.getRayInformation().checkRaysFront(gravityClient, 0.0f, entity.getTransform().eulerAngles.z + 0.0f, layermask);
#endif
            if (keysPressed.jump && (gravity.isStanding() ||
#if USE_3D_RAYS
                                     (gravityClient.getRayHitboxes().DistanceBelow <= (gravityClient.getRayInformation3D().MinimalSpaceBetweenTileBelow))) &&
#else
                                     (gravityClient.getRayHitboxes().DistanceBelow <= (gravityClient.getRayInformation().MinimalSpaceBetweenTileBelow))) &&
#endif
                entity.getJumpedReleased())
            {
                IBehaviourStateFactory behaviourStateFactory = entity.getBehaviourStateFactory();
                entity.setState(behaviourStateFactory.getJumpUpState(entity));
                moveEntity(entity, keysPressed, gravity, entity.getMovementSpeed());
            }
예제 #8
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);
        }
예제 #9
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);
        }
예제 #10
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);
        }
예제 #11
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);
        }