Ejemplo n.º 1
0
        protected override Direction CalculateNextDirection()
        {
            offset = targetTrans.position - transform.position;

            //Find the min angle between the offset vector and eight direction
            float minAngle = Vector2.Angle(offset, CommonConstants.DIRECTION_VECTORS[0]);
            int   minIndex = 0;

            for (int i = 1; i < CommonConstants.DIRECTION_VECTORS.Length; i++)
            {
                float angle = Vector2.Angle(offset, CommonConstants.DIRECTION_VECTORS[i]);

                if (angle <= minAngle)
                {
                    minAngle = angle;
                    minIndex = i;
                }
            }
            return(UtilMapHelpers.VectorToDirection(CommonConstants.DIRECTION_VECTORS[minIndex]));
        }
Ejemplo n.º 2
0
        protected override Direction CalculateNextDirection()
        {
            offset = targetTrans.position - transform.position;

            //Init cache value
            Vector2[] directionVectors       = CommonConstants.DIRECTION_VECTORS;
            int       directionVectorsLength = directionVectors.Length;

            //Find the movable neighbor direction of enemy
            List <Vector2> movableDirection = new List <Vector2>();

            for (int i = 0; i < directionVectorsLength; i++)
            {
                if (IsMovable(directionVectors[i]))
                {
                    //Debug.Log("Movable direction: " + UtilMapHelpers.VectorToDirection(directionVectors[i]));
                    movableDirection.Add(directionVectors[i]);
                }
            }


            //Find the min direction in the movable direction vector list
            float minAngle = Vector2.Angle(offset, movableDirection[0]);
            int   minIndex = 0;

            for (int i = 1; i < movableDirection.Count; i++)
            {
                float angle = Vector2.Angle(offset, movableDirection[i]);

                if (angle <= minAngle)
                {
                    minAngle = angle;
                    minIndex = i;
                }
            }

            //Convert vector to direction
            return(UtilMapHelpers.VectorToDirection(movableDirection[minIndex]));
        }