Advertisement
Guest User

Gaussian

a guest
Jun 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.82 KB | None | 0 0
  1. float x = 0;
  2. float posX = 0;
  3. const float MAXINTERVAL = 5;
  4. while (x < 1)
  5. {
  6.     // 1 / amount of objects on spline
  7.     var temp = Instantiate(inst);
  8.     temp.transform.position = new Vector3(posX, 0, 0);
  9.     x += 1f / 11f;
  10.     posX += MAXINTERVAL - Gaussian(3f, 0.5f, 0.25f, x);
  11.     Debug.Log(Gaussian(28f, 0.5f, 2, x));
  12. }
  13.  
  14. private float Gaussian(float a, float b, float c, float x)
  15.     {
  16.         //'a' is the height of the curve
  17.         //'b' is the center of the curve (i.e. the highest point, if 'b' = 2, the result will be 'a' if 'x' = 2)
  18.         //'c' is the width of the curve
  19.         //    
  20.         //                .-.
  21.         //               /   \
  22.         //              /     \
  23.         //     ___,,..-'       '-..,,___
  24.         //
  25.         return a * Mathf.Exp(-((Mathf.Pow((x - b), 2)) / (2 * Mathf.Pow(c, 2))));
  26.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement