Example #1
0
        private void HandleNeighbour(Face neighbour)
        {
            if (neighbour == null || (neighbour.AreaMask & agentAreaMask) == 0 || closeSet.Contains(neighbour))
            {
                return;
            }
            var neighbourCenter = neighbour.CalculateCenter();

            float neighbourDistance          = Vector3.Distance(currentCenter, neighbourCenter);
            float neighbourDistanceCostBonus = (neighbour.Weight * neighbourDistance - neighbourDistance) / 2;

            float possibleGCost = current.gCost + neighbourDistance + neighbourDistanceCostBonus;

            var neighbourSetElement = openSet.BruteFind((e) => e.face == neighbour);

            if (neighbourSetElement == null)
            {
                openSet.Add(new FaceStarUnit(neighbour, current, possibleGCost, Vector3.Distance(neighbourCenter, endCenter) + neighbourDistanceCostBonus));
            }
            else if (possibleGCost < neighbourSetElement.gCost)
            {
                openSet.Remove(neighbourSetElement);
                neighbourSetElement.Update(current, possibleGCost, Vector3.Distance(neighbourCenter, endCenter) + neighbourDistanceCostBonus);
                openSet.Add(neighbourSetElement);
            }
        }