Advertisement
Guest User

New Recoil System

a guest
Oct 21st, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 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. Random rnd = new Random();
  11. currentRecoil = evalRecoil(currentRecoil[0], 0.3f, 0.3f, rnd);
  12. Console.WriteLine(i + ":\nUp: " + currentRecoil[0] + "\nSides: " + currentRecoil[1] + "\n");
  13. }
  14. }
  15.  
  16. public static float[] evalRecoil(float currentUp, float upMultiplier, float sideMultiplier, Random rng){
  17. float[] toReturn = new float[2];
  18.  
  19. if (currentUp == 0) {
  20. currentUp = 0.1f;
  21. }
  22.  
  23. sideMultiplier += (sideMultiplier * currentUp);
  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