Advertisement
Guest User

Untitled

a guest
Nov 16th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.89 KB | None | 0 0
  1. public Collision Collision(Entity e)
  2.         {
  3.             float rad = (Radius + Radius) * (e.Radius + e.Radius);
  4.  
  5.             //Pos delta
  6.             float px = X - e.X;
  7.             float py = Y - e.Y;
  8.  
  9.             //Vel delta
  10.             float vx = Vx - e.Vx;
  11.             float vy = Vy - e.Vy;
  12.  
  13.             if (vx == 0 && vy == 0)
  14.                 return null;
  15.  
  16.             float a = (vx * vx) + (vy * vy);
  17.             float b = ((vx * px) + (vy * py)) * 2;
  18.             if (b >= 0)
  19.                 return null;
  20.  
  21.             float c = ((px * px) + (py * py)) - rad;
  22.  
  23.             float d = b * b - 4 * a * c;
  24.             if (d < 0)
  25.                 return null;
  26.  
  27.             float t = (-b - (float) Math.Sqrt(d)) / (2 * a);
  28.  
  29.             if(t < 0)
  30.                 Console.Error.WriteLine("WTF THERE IS INFINITE LOOP STILL");
  31.  
  32.             return new Collision(this, e, t);
  33.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement