// Use this for initialization void Start() { // round position properly Vector3 myPosition = this.transform.position; myPosition.x = Mathf.Round(myPosition.x); myPosition.y = Mathf.Round(myPosition.y); myPosition.z = Mathf.Round(myPosition.z); this.transform.position = myPosition; powerupGenerate = new RandomXORShift(); powerupGenerate.seed = seed; // generate level Generate(); }
// Perlin Noise Function public float PerlinNoiseGenerate(float point1, float point2) { //setup variables (more boring stuff) float valReturn = 0; float interpolate1; float interpolate2; float interpolated; int res = resolution; RandomXORShift rand1 = new RandomXORShift(); RandomXORShift rand2 = new RandomXORShift(); RandomXORShift rand3 = new RandomXORShift(); RandomXORShift rand4 = new RandomXORShift(); // Loop to get the data from each octave for (int ctr = 1; ctr < detail; ctr++) { // make boxes smaller each octave res = res / 2; rand1.seed = seed + Mathf.RoundToInt((Mathf.FloorToInt(point1 / res) * -7) + (Mathf.FloorToInt(point2 / res) * 3)); rand2.seed = seed + Mathf.RoundToInt((Mathf.FloorToInt((point1 + res) / res) * -7) + (Mathf.FloorToInt(point2 / res) * 3)); rand3.seed = seed + Mathf.RoundToInt((Mathf.FloorToInt(point1 / res) * -7) + (Mathf.FloorToInt((point2 + res) / res) * 3)); rand4.seed = seed + Mathf.RoundToInt((Mathf.FloorToInt((point1 + res) / res) * -7) + (Mathf.FloorToInt((point2 + res) / res) * 3)); // interpolation interpolate1 = RandomXORShift.interpolateCosine(rand1.range(0, 2), rand2.range(0, 2), point1 - (Mathf.FloorToInt(point1 / res) * res), res); interpolate2 = RandomXORShift.interpolateCosine(rand3.range(0, 2), rand4.range(0, 2), point1 - (Mathf.FloorToInt(point1 / res) * res), res); interpolated = RandomXORShift.interpolateCosine(interpolate1, interpolate2, point2 - (Mathf.FloorToInt(point2 / res) * res), res); // add octave value to point; each octave has half as much influence as the one before it valReturn += interpolated * Mathf.Pow(2, -ctr); } return(valReturn); }