Beispiel #1
0
    private void PopulatePaths()
    {
        paths = new List <AI_Path>();

        Vector3 upperPosition = transform.position;

        lowerPosition = new Vector3(transform.position.x, lowPoint, transform.position.z);

        float yHeight = Mathf.Abs(upperPosition.y - lowerPosition.y) / rows;

        sniperPath = new AI_Path(new Vector3(upperPosition.x, upperPosition.y + yHeight, upperPosition.z), new Vector3(upperPosition.x + rowWidth, upperPosition.y + yHeight, upperPosition.z), true, -1);

        float rowDepthsAdds = 0f;

        for (int i = 0; i < rows; i++)
        {
            float   yValue        = upperPosition.y - (yHeight * i);
            Vector3 startPosition = upperPosition;
            startPosition.y = yValue;
            Vector3 endPosition = startPosition;
            endPosition.x   += rowWidth;
            startPosition.z += (rowDepthsAdds + rowDepths);
            endPosition.z   += (rowDepthsAdds += rowDepths);
            AI_Path path = new AI_Path(startPosition, endPosition, i % 2 == 0, i);
            paths.Add(path);
        }
    }
Beispiel #2
0
    public static AI_Path GetNearestPath(float yPosition)
    {
        AI_Path pathToReturn = default;
        float   y            = float.MaxValue;

        foreach (AI_Path path in instance.paths)
        {
            float distance = Mathf.Abs(yPosition - path.StartPosition.y);
            if (distance < y)
            {
                y            = distance;
                pathToReturn = path;
            }
        }
        return(pathToReturn);
    }
Beispiel #3
0
    void OnDrawGizmos()
    {
        if (Application.isPlaying == false)
        {
            if (instance == null)
            {
                instance = this;
            }

            PopulatePaths();

            for (int i = 0; i < rows; i++)
            {
                AI_Path path = paths[i];
                Gizmos.color = Color.green;
                Gizmos.DrawLine(path.StartPosition, path.EndPosition);
            }

            Gizmos.color = Color.blue;
            Gizmos.DrawLine(sniperPath.StartPosition, sniperPath.EndPosition);
        }
    }