// Code to split current node (blue) with intersecting node (red). // Each shape is a rectangle // The current node's next shape I will refer to as Transformation // The new node will be referred to as Instantiated public void OnFoundIntersection(GameObject intersector, float intersectorWidth) { // Code to split current node (blue) with intersecting node (red). // Each shape is a rectangle // The current node's next shape I will refer to as Transformation // The new node will be referred to as Instantiated float widthRed = intersector.transform.localScale.x; Vector3 centerRed = intersector.transform.position; Vector3 centerBlue = transform.position; // the red node's horizontal dimension is parallel to the blue node's. float transformationWidth = Mathf.Max(Vector2.Distance(centerRed, leftBoundPosition) - .5f * widthRed, 0); float instantiatedWidth = Mathf.Max(Vector2.Distance(rightBoundPosition, centerRed) - .5f * widthRed, 0); Vector3 transformationMidpoint = new Vector3(leftBoundPosition.x + .5f * transformationWidth * Mathf.Cos(angle), leftBoundPosition.y + .5f * transformationWidth * Mathf.Sin(angle), 0); Vector3 instantiatedMidpoint = new Vector3(rightBoundPosition.x - .5f * instantiatedWidth * Mathf.Cos(angle), rightBoundPosition.y - .5f * instantiatedWidth * Mathf.Sin(angle), 0); // now, relocate & resize current node (it will become the left half) transform.localScale = new Vector3(transformationWidth, transform.localScale.y, transform.localScale.z); transform.SetPositionAndRotation(transformationMidpoint, transform.rotation); // Instantiate right half of blue node. GameObject floorNodeGameObject = Instantiate(floorNodePrefab); floorNodeGameObject.transform.localScale = new Vector3(instantiatedWidth, transform.localScale.y, transform.localScale.z); floorNodeGameObject.transform.SetPositionAndRotation(instantiatedMidpoint, transform.rotation); FloorNode newFloorNode = floorNodeGameObject.AddComponent <FloorNode>(); // Terrain that owns this floorNode needs to have its list of floor nodes updated. // I believe that this will ensure that all of the instantiated nodes will be checked prior to // the terrain giving the all-go. if (owner != null) { newFloorNode.owner = owner; newFloorNode.owner.ownedFloorNodes.Add(this); } ActionNode intersectingNode = intersector.GetComponent <ActionNode>(); intersectingNode.SetLeftNeighbor(this);//gameObject.GetComponent<NG2D_WalkNode>() intersectingNode.SetRightNeighbor(newFloorNode); newFloorNode.SetLeftNeighbor(intersectingNode); Node rightNeighbor = GetRightNeighbor(); if (rightNeighbor != null) { newFloorNode.SetRightNeighbor(rightNeighbor); rightNeighbor.SetLeftNeighbor(newFloorNode); } SetRightNeighbor(intersectingNode); navGraphPreLauncher.RemoveIntersectorFromActionNodeList(intersector); // NOTE: I must implement the above function before I can uncomment the line below. newFloorNode.CheckIntersections(); }