/// <summary> /// Create a new node at the given index. /// This creates a node at the given index /// by creating box hits in all directions /// </summary> /// <param name="x"> X index </param> /// <param name="y"> Y index </param> /// <param name="z"> Z Index </param> private void AddNewNodeBoxGraph(int x, int y, int z) { // Get the correct world space information float posX = gridStartPosition.x + (x * nodeDistance); float posZ = gridStartPosition.z + (z * nodeDistance); float posY = gridStartPosition.y + (y * heightStep); //Create a new node and update it's values Vector3 pos = new Vector3(posX, posY, posZ); RaycastHit[] hits = new RaycastHit[0]; if (CheckForward) { hits = hits.AddArray(GetBoxColliderHits(Vector3.forward, new Vector3(pos.x, pos.y, pos.z))); } if (CheckBack) { hits = hits.AddArray(GetBoxColliderHits(-Vector3.forward, new Vector3(pos.x, pos.y, pos.z))); } if (CheckDown) { hits = hits.AddArray(GetBoxColliderHits(Vector3.down, new Vector3(pos.x, pos.y, pos.z))); } if (CheckUp) { hits = hits.AddArray(GetBoxColliderHits(-Vector3.down, new Vector3(pos.x, pos.y, pos.z))); } if (CheckLeft) { hits = hits.AddArray(GetBoxColliderHits(-Vector3.right, new Vector3(pos.x, pos.y, pos.z))); } if (CheckRight) { hits = hits.AddArray(GetBoxColliderHits(Vector3.right, new Vector3(pos.x, pos.y, pos.z))); } // Create the node and determine it options Node node = new Node(x, y, z, pos, NodeType.Open); DetermineNodeTypeHit(hits, ref node); node.distanceTraveled = Vector3.Distance(node.Position, objectStartPosition); calculateStartNode(node); // then place it to the grid Nodes[x, y, z] = node; }