//called by passing through a node's collider (or automatically in a coroutine to test) public void SpawnInNextNode() { //if(currentNodeIndex >= nodeLimit){return;} //Calculate the offset from the last transform Transform lastTransform = (currentNodeIndex < 1) ? this.transform : activeNodes[activeNodes.Count - 1].transform; float spawnOffsetH = seededGradient.GetHorizontalValueAtPixel(currentNodeIndex); float spawnOffsetV = seededGradient.GetVerticalValueAtPixel(currentNodeIndex); spawnOffsetH = ReedsUtils.Remap(spawnOffsetH, 0, 1, -amplitudeDelta, amplitudeDelta); spawnOffsetV = ReedsUtils.Remap(spawnOffsetV, 0, 1, -amplitudeDelta, amplitudeDelta); Vector3 totalOffsetFromLast = lastTransform.position + lastTransform.right * spawnOffsetH + lastTransform.up * spawnOffsetV; totalOffsetFromLast += lastTransform.forward * spacing; //Instantiate new node LinkedNode newNode = Instantiate(template, totalOffsetFromLast, Quaternion.identity); Quaternion lookatRot = Quaternion.LookRotation(newNode.transform.position - lastTransform.position, Vector3.up); newNode.transform.rotation = Quaternion.Slerp(lastTransform.rotation, lookatRot, bendFactor); newNode.SetMeshRot(lookatRot); newNode.SetMaterial(ref availibleKits[currentKitIndex].material); //Append to activenodes, and set links if (activeNodes.Count > 0) // else this is the first node { activeNodes[activeNodes.Count - 1].previous = newNode; newNode.previous = activeNodes[activeNodes.Count - 1]; } activeNodes.Add(newNode); currentNodeIndex++; //if trackedNodesList len >= recyclethreshold //recycle oldest node(at index 0) if (activeNodes.Count >= recycleThreshold) { //Debug.Log("Recycling"); GameObject toDestroy = activeNodes[0].gameObject; activeNodes.RemoveAt(0); GameObject.Destroy(toDestroy); } CheckForNewZone(); CheckPositionOffset(lastTransform); }
private IEnumerator SpawnChildrenCoroutine() { float sampleGradientPoint = GlobalVars.worldGradient.GetHorizontalValueAtPixel((int)(indexInChain * rotationalChaos)); ; //float sampleGradientPointB = GlobalVars.worldGradient.GetVerticalValueAtPixel(indexInChain); int generations = (int)(sampleGradientPoint * childrenDensity); System.Random r = new System.Random(indexInChain); for (int i = 0; i < generations; i++) { int offset = i + indexInChain; offset = i * (int)transform.position.magnitude; //Debug.Log(indexInChain); //offset = (int)(GlobalVars.worldGradient.GetVerticalValueAtPixel(offset) * 100); float forwardPos = 0; forwardPos = GlobalVars.worldGradient.GetHorizontalValueAtPixel(offset * samplRate); forwardPos = r.Next(100); //Debug.Log($"Sample point at {forwardPos} with sample pos at {offset * samplRate}"); //Debug.Log($"Raw pos is {forwardPos}"); forwardPos = ReedsUtils.Remap(forwardPos, 0, 100, -maxForwardDelta, maxForwardDelta); //Debug.Log($"mapped pos is {forwardPos}"); float zRotation = GlobalVars.worldGradient.GetHorizontalValueAtPixel(offset * samplRate); //zRotation = GlobalVars.worldGradient.GetNoiseAtPixel(offset * samplRate * 33333, offset * samplRate * 33333); //Debug.Log($"Raw zrot is {zRotation}"); zRotation = r.Next(100); zRotation = ReedsUtils.Remap(zRotation, 0, 100, 0, 720); //Debug.Log($"mapped zrot is {zRotation}"); //float kitOffset = GlobalVars.worldGradient.GetNoiseAtPixel(offset * samplRate, offset); //float kitOffset = GlobalVars.worldGradient.GetHorizontalValueAtPixel(offset * samplRate); int kitOffset = r.Next(0, localKit.kitObjects.Count); //int kitIndex = (int)ReedsUtils.Remap(kitOffset, 0, 100, 0, currentKit.kitObjects.Count - .1f); GameObject kitPiece = Instantiate(localKit.kitObjects[kitOffset], transform.GetChild(0), false); kitPiece.transform.localEulerAngles = new Vector3(0, 0, zRotation); kitPiece.transform.localPosition = new Vector3(0, 0, forwardPos); //Debug.Log(kitOffset); yield return(null); } }