Beispiel #1
0
    private Vector2 GetTargetPosition()
    {
        Vector2 result = transform.position;

        int[] flowField = flock.Flowfield;
        int   currRegion;

        if (flowField != null && flowField.Length > 0)
        {
            currRegion = mesh.NavigationRegionIdFromGridSpacePosition(transform.position);

            // flowField[currRegion] is the region that we want to move towards FROM our
            // current region. So if flowField[currRegion] = currRegion, then our goal is in
            // the same region as we are. Thus we can move directly towards it.
            if (currRegion != -1 && flowField[currRegion] != currRegion)
            {
                result = mesh.GetRegionCenterInGridSpace(flowField[currRegion]);
            }
            else
            {
                result = target.transform.position;
            }
        }

        return(result);
    }