//Actually sets path and initiates path index
        public void StartNavigation(int goalX, int goalY)
        {
            if (waypointGraph == null)
            {
                Debug.LogWarning("Cant Start Navigation, due to Waypoint Graph not being initialized yet");
                return;
            }

            Waypoint start = waypointGraph.FindClosestWaypoint(transform.position);
            Waypoint goal  = waypointGraph.FindClosestWaypoint(new Vector3(goalX, 0f, goalY));

            Waypoint accurateStart = new Waypoint((int)transform.position.x, (int)transform.position.z);
            Waypoint accurateGoal  = goal;

            if (goal.X != goalX || goal.Y != goalY)
            {
                accurateGoal = new Waypoint(goalX, goalY);                 //Custom Location
            }
            //Naive Movement Optimization
            if (optimizePath)
            {
                if (IsPathClearBetweenWaypoints(accurateStart, accurateGoal))
                {
                    path = new List <Waypoint>();
                    path.Add(accurateGoal);
                    Debug.Log("Simple navigation since path is clear");
                    pathIndex = 0;
                    return;
                }
            }

            path = waypointGraph.AStar(start, goal);

            //path.Insert(0, accurateStart); //O(n)
            if (goal.X != goalX || goal.Y != goalY)
            {
                path.Add(accurateGoal);
            }


            if (path.Count > 1)
            {
                if (IsPathClearBetweenWaypoints(accurateStart, path[1]))
                {
                    path.RemoveAt(0);
                }
            }
            if (strongOptimizePath)
            {
                OptimizePath();
            }
            pathIndex = 0;
        }
예제 #2
0
        //Actually sets path and initiates path index
        public void StartNavigation(int goalX, int goalY)
        {
            if (waypointGraph == null)
            {
                Debug.LogWarning("Cant Start Navigation, due to Waypoint Graph not being initialized yet");
                return;
            }
            Waypoint start = waypointGraph.FindClosestWaypoint(transform.position);
            Waypoint goal  = waypointGraph.FindClosestWaypoint(new Vector3(goalX, 0f, goalY));

            path      = waypointGraph.AStar(start, goal);
            pathIndex = 0;
        }
예제 #3
0
        //Actually sets path and initiates path index
        public void StartNavigation(int goalX, int goalY)
        {
            if (waypointGraph == null)
            {
                Debug.LogWarning("Cant Start Navigation, due to Waypoint Graph not being initialized yet");
                return;
            }

            Waypoint start = waypointGraph.FindClosestWaypoint(transform.position);
            Waypoint goal  = waypointGraph.FindClosestWaypoint(new Vector3(goalX, 0f, goalY));

            path = waypointGraph.AStar(start, goal);
            if (goal.X != goalX || goal.Y != goalY)
            {
                path.Add(new Waypoint(goalX, goalY));                 //Custom Location
            }
            OptimizePath();
            pathIndex = 0;
        }