Example #1
0
        public override Goal Decompose(KinematicData character, Goal goal)
        {
            AStarPathfinding Astar = new NodeArrayAStarPathFinding(Graph, Heuristic);
            Astar.InitializePathfindingSearch(character.position, goal.position);

            // In goal, ends
            if (Astar.StartNode.Equals(Astar.GoalNode)) {
                return goal;
            }
            // else, plan
            GlobalPath currentSolution;
            if (Astar.InProgress)
            {
                var finished = Astar.Search(out currentSolution, true);
                if (finished && currentSolution != null)
                {
                    // gets first node
                    goal.position = currentSolution.PathNodes[0].Position;
                   return goal;
                }
            }
            return goal;
        }