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; }
public void init() { //set ref GameObject agent = Ref.getActiveAgent(); GameObject managerGO = Ref.getManagerGO(); GameObject plane = Ref.getPlane(); managerScript = managerGO.GetComponent <Manager>(); findPathScript = agent.GetComponent <FindPath>(); followPathScript = agent.GetComponent <FollowPath>(); agentPropsScript = agent.GetComponent <AgentProps>(); visObstManagerScript = agent.GetComponent <VisibleObstManager>(); nodeDiameter = nodeRadius * 2; if (levelTxt != null) { lines = levelTxt.text.Split('\n'); string firstLine = lines[0]; gridWorldSize.x = int.Parse(firstLine.Split(' ')[0]); gridWorldSize.y = int.Parse(firstLine.Split(' ')[1]); } GridSizeX = Mathf.RoundToInt(gridWorldSize.x / nodeDiameter); GridSizeY = Mathf.RoundToInt(gridWorldSize.y / nodeDiameter); GridSizeZ = agentPropsScript.cooperationLenght * 2 + 1; plane.transform.localScale = new Vector3(GridSizeX / 10f, 1, GridSizeY / 10f); worldBottomLeft = transform.position - Vector3.right * gridWorldSize.x / 2 - Vector3.forward * gridWorldSize.y / 2; CreateGrid(); }
void Start() { managerScript = Ref.getManagerGO().GetComponent <Manager>(); gridScript = Ref.getGridScript(); visibleObstManagerScript = GetComponent <VisibleObstManager>(); agentPropsScript = GetComponent <AgentProps>(); saveInitalGrid(); agent = transform; spatialAStarScript = GetComponent <SpatialAStar>(); spatialAStarScript.init(grid); managerScript.increaseFrameCount(); path = spatialAStarScript.FindPathSpatial(agent.position, target.position, true, null); followPathScript = agent.GetComponent <FollowPath>(); followPathScript.init(); followPathScript.setNewPath(path); }