Beispiel #1
0
    public int GetPathClosestToFacing()
    {
        int   closestAngleIndex = 0;
        float closestAngle      = float.MaxValue;

        for (int i = 0; i < availablePaths.Count; i++)
        {
            Vector3 next      = pathGraph.GetOtherNode(currentNode, availablePaths[i]).transform.position;
            Vector3 rel       = next - currentNode.transform.position;
            float   nodeAngle = Vector3.Angle(rel, transform.forward);
            if (nodeAngle < closestAngle)
            {
                closestAngleIndex = i;
                closestAngle      = nodeAngle;
            }
        }

        return(closestAngleIndex);
    }