private void AddInstanceObj(List <InstancingObj> currentBatch, Matrix4x4[] currentMatrix, int index, int i) { float dist = 50f; float deg = instances / 360f; float rad = (deg * (float)i) * Mathf.Deg2Rad; float x = Mathf.Cos(rad) * dist; float z = Mathf.Sin(rad) * dist; float scaleVal = Random.Range(-0.1f, 0.3f); Vector3 pos = new Vector3(x + Random.Range(-maxPos.x, maxPos.x), Random.Range(-maxPos.y, maxPos.y), z + Random.Range(-maxPos.x, maxPos.y)); InstancingObj obj = new InstancingObj(pos, new Vector3(0.3f + scaleVal, 0.3f + scaleVal, 0.3f + scaleVal), Quaternion.Euler(Random.Range(-360f, 360f), Random.Range(-360f, 360f), Random.Range(-360f, 360f))); currentBatch.Add(obj); currentMatrix[index] = obj.matrix; }
private void UpdateTRS(float scalVal = 1f) { time += Time.deltaTime; int index = 0; for (int i = 0; i < batches.Count; i++) { for (int j = 0; j < batches[i].Count; j++) { InstancingObj obj = batches[i][j]; Vector3 pos = obj.pos; float noise = Mathf.PerlinNoise(pos.x, pos.y); pos.y += Mathf.Sin(time * noise); matrixList[i][j] = Matrix4x4.TRS(pos, obj.rot, obj.scale); index++; } } }