Example #1
0
        // Публичные методы
        public static List <Node> FindPath(NavigationGraph navigationGraph,
                                           NavigationAgent navigationAgent,
                                           NavigationNode destination)
        {
            Node temporaryPathOriginNode = navigationGraph.Graph.AddNode(navigationAgent.transform.position);

            Arc temporaryBackArc = navigationGraph.Graph.AddArc(temporaryPathOriginNode,
                                                                navigationAgent.RareNode,
                                                                Directedness.Undirected);

            Arc temporaryForwardArc = navigationGraph.Graph.AddArc(temporaryPathOriginNode,
                                                                   navigationAgent.FrontNode,
                                                                   Directedness.Undirected);

            IPath path = FindGraphPath(navigationGraph, navigationAgent, destination);

            List <Node> pathAsNodeList = PathToNodeList(path);

            DeleteTemporaryNodeAndArcs(navigationGraph,
                                       temporaryPathOriginNode,
                                       temporaryForwardArc,
                                       temporaryBackArc);

            return(pathAsNodeList);
        }
Example #2
0
        private void ChangeHeroRotation(Transform heroDragPoint, NavigationAgent heroNavigationAgent)
        {
            Quaternion targetRotation =
                Quaternion.LookRotation(heroNavigationAgent.FrontNode.Coordinate - heroDragPoint.position);

            // Обнуляем x-компоненту, дабы модель героя не наклонялась на горках.
            targetRotation = Quaternion.Euler(0, targetRotation.eulerAngles.y, targetRotation.eulerAngles.z);

            heroDragPoint.rotation = Quaternion.RotateTowards(heroDragPoint.rotation,
                                                              targetRotation,
                                                              Time.deltaTime * heroRotationSpeed);
        }
Example #3
0
        // Приватные методы
        private static IPath FindGraphPath(NavigationGraph navigationGraph,
                                           NavigationAgent navigationAgent,
                                           NavigationNode destination)
        {
            IPath pathBack = navigationGraph.Graph.FindPath(navigationAgent.RareNode,
                                                            destination.Node,
                                                            Dfs.Direction.Undirected);

            IPath pathForward = navigationGraph.Graph.FindPath(navigationAgent.FrontNode,
                                                               destination.Node,
                                                               Dfs.Direction.Undirected);

            IPath shortestPath = pathBack.NodeCount() > pathForward.NodeCount() ? pathForward : pathBack;

            return(shortestPath);
        }
Example #4
0
 private void ChangeHeroPosition(Transform heroDragPoint, NavigationAgent heroNavigationAgent)
 {
     heroDragPoint.position = Vector3.MoveTowards(heroDragPoint.position,
                                                  heroNavigationAgent.FrontNode.Coordinate,
                                                  Time.deltaTime * heroMovementSpeed);
 }