Heracles421

Bullet Drop Calc

Jul 24th, 2015
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 KB | None | 0 0
  1. // calculated bullet drop
  2.                             targetDrop.X = (float) (Math.Pow(aimTarget.Distance, 2) - Math.Pow(AIM3D.Y, 2));
  3.                             targetDrop.Y = AIM3D.Y - Main.Player.Position.Y;
  4.                             dropAngle = (float)Math.Atan((Math.Pow(startSpeed, 2) - Math.Sqrt(Math.Pow(startSpeed, 4) - 9.81 * (9.81 * Math.Pow(targetDrop.X, 2) + 2 * targetDrop.Y * Math.Pow(startSpeed, 2)))) / (9.81 * targetDrop.X));
  5.  
  6.                             A1 = (float)Math.Tan(dropAngle) - 0;
  7.                             B1 = 0-1;
  8.                             C1 = A1 * 0 + B1 * 0;
  9.  
  10.                             A2 = (targetDrop.Y + 1) - targetDrop.Y;
  11.                             B2 = targetDrop.X - targetDrop.X;
  12.                             C2 = A1 * 0 + B1 * targetDrop.Y;
  13.  
  14.                             float det = A1*B2 - A2*B1;
  15.                             if(det == 0)
  16.                             {
  17.                                 //Lines are parallel
  18.                             }
  19.                             else
  20.                             {
  21.                                 lineInterX = (B2 * C1 - B1 * C2) / det;
  22.                                 lineInterY = (A1 * C2 - A2 * C1) / det;
  23.                             }
  24.                             AIM3D.Y += lineInterX - targetDrop.Y;
  25.                             AIM = Graphics.W2S(AIM3D); // project to screen
Advertisement
Add Comment
Please, Sign In to add comment