예제 #1
0
    public void init()
    {
        if (initComplete == false)
        {
            //set ref
            gridScript           = Ref.getGridScript();
            visibleObstManager   = GetComponent <VisibleObstManager>();
            managerScript        = Ref.getManagerGO().GetComponent <Manager>();
            recalculateTime      = GetComponent <AgentProps>().cooperationLenght;
            spatialAStarScript   = GetComponent <SpatialAStar>();
            spaceTimeAStarScript = GetComponent <SpaceTimeAStar>();
            agent            = transform;
            followPathScript = agent.GetComponent <FollowPath>();

            //saves initial grid in grid var
            saveInitalGrid();

            spaceTimeAStarScript.init();
            spatialAStarScript.init(grid);
            spaceTimeAStarScript.setSpacialAStarScript(spatialAStarScript);
            managerScript.increaseFrameCount();

            //here we switch the role of target and agent
            spatialAStarScript.FindPathSpatial(target.position, agent.position, true, null);

            path = spaceTimeAStarScript.FindPath(agent.position, target.position, true);

            followPathScript.init();
            followPathScript.setNewPath(path);
        }
        initComplete = true;
    }
예제 #2
0
    //triggers when predicted obstacle path crosses current agent path
    public void recaluclateOnObstaclePathIntercept()
    {
        //get starting node
        Node newStartNode = followPathScript.getNextNodeToBeVisited();
        int  debugTime    = followPathScript.getCurrentTimeFrame();

        prevPath = path;

        clearPathInGrid();

        //get new path
        if (newStartNode.worldPosition != target.position)
        {
            managerScript.increaseFrameCount();
            List <Node> currentPath = spaceTimeAStarScript.FindPath(newStartNode.worldPosition, target.position, true);
            if (currentPath != null)
            {
                path = currentPath;

                //the path is primed so that it get's swapped out only when an agent reaches the center of his next cell
                followPathScript.primeNewPath(currentPath);

                //this is done so that if there is a second recalc before the path is reset the obstacle path won't be shifted
                //as it has already been reset by the previous recalc
                followPathScript.resetLastFrame();
            }
            //this means agent got stuck and restart of spatial A* is needed
            else
            {
                restartPath();
                return;
            }
        }
        //mark path
        foreach (Node node in path)
        {
            gridScript.markNode(node, false, true);
        }

        //restart time for getting new chunk
        prevTime = Time.time;
    }