Example #1
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);
        }
Example #2
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);
        }