Advertisement
Guest User

Recoil Code

a guest
Oct 21st, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. using System;
  2.  
  3. public class Program
  4. {
  5. public static void Main()
  6. {
  7. float[] currentRecoil = new float[2];
  8.  
  9. for (int i = 0; i < 30; i++) {
  10. //currentRecoil = evalRecoil(currentRecoil[0], 0.6f, 0.3f);
  11. //Console.WriteLine(i + ":\nUp: " + currentRecoil[0] + "\nSides: " + currentRecoil[1] + "\n");
  12. Random rand = new Random();
  13. float myVal = (float.MaxValue * ((rand.Next() / 1073741824.0f) - 1.0f));
  14. Console.WriteLine(myVal);
  15. }
  16. }
  17.  
  18. public static float[] evalRecoil(float currentUp, float upMultiplier, float sideMultiplier, Random rng){
  19. float[] toReturn = new float[2];
  20.  
  21. if (currentUp == 0) {
  22. currentUp = 0.1f;
  23. }
  24.  
  25. float up = (currentUp * upMultiplier) + currentUp;
  26.  
  27. float sideCalc = (currentUp * sideMultiplier);
  28.  
  29. Console.WriteLine("Debug sideCalc: " + sideCalc);
  30.  
  31. float side = randomFloat(-sideCalc, sideCalc, rng);
  32.  
  33. if (up > 20) {
  34. up = 20; }
  35. if (side > 10) {
  36. side = 10; }
  37. if (side < -10) {
  38. side = -10;}
  39.  
  40. toReturn[0] = up;
  41. toReturn[1] = side;
  42.  
  43. return toReturn;
  44. }
  45.  
  46. public static float randomFloat(float min, float max, Random rng){
  47. double range = (double) max - (double) min;
  48. double sample = rng.NextDouble();
  49. double scaled = (sample * range) + min;
  50. float f = (float) scaled;
  51. return f;
  52. }
  53.  
  54. static float NextFloat(float max, float min, Random rand)
  55. {
  56. return (float)(max * 2.0 * (rand.NextDouble()-0.5));
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement