Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Collision Collision(Entity e)
- {
- float rad = (Radius + Radius) * (e.Radius + e.Radius);
- //Pos delta
- float px = X - e.X;
- float py = Y - e.Y;
- //Vel delta
- float vx = Vx - e.Vx;
- float vy = Vy - e.Vy;
- if (vx == 0 && vy == 0)
- return null;
- float a = (vx * vx) + (vy * vy);
- float b = ((vx * px) + (vy * py)) * 2;
- if (b >= 0)
- return null;
- float c = ((px * px) + (py * py)) - rad;
- float d = b * b - 4 * a * c;
- if (d < 0)
- return null;
- float t = (-b - (float) Math.Sqrt(d)) / (2 * a);
- if(t < 0)
- Console.Error.WriteLine("WTF THERE IS INFINITE LOOP STILL");
- return new Collision(this, e, t);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement