1.12k likes | 1.15k Views
Dive into tunneling, movement bounds, and swept shapes to understand and prevent glitches in game physics. Learn how to reframe the problem and tackle false positives and negatives with Einstein and Minkowski. Discover practical solutions for collision detection and prevention.
E N D
Physics for Games Programmers Reframing the Problem Squirrel EiserlohTechnical DirectorMumboJumbo Gamessquirrel@eiserloh.netwww.algds.org
Physics for Games Programmers Reframing the Problema.k.a. “It’s All Relative” Squirrel EiserlohTechnical DirectorMumboJumbo Gamessquirrel@eiserloh.netwww.algds.org
Overview • Tunneling • Movement Bounds • Swept Shapes • Einstein Says... • Minkowski Says... • Rotation
Tunneling (Sucks)
Tunneling • Question #1: Do objects A and B overlap? • Plenty of reference material to help solve this, but... • ...this is often the wrong question to ask (begs tunneling).
Tunneling (cont’d) • Tunneling is very, very bad – this is not a “mundane detail” • Things falling through world • Bullets passing through people or walls • Players getting places they shouldn’t • Players missing a trigger boundary • Tunneling is a false negative • Okay, so tunneling really sucks. What can we do about it?
Movement Bounds • Disc / Sphere
Movement Bounds • Disc / Sphere • AABB (Axis-Aligned Bounding Box)
Movement Bounds • Disc / Sphere • AABB (Axis-Aligned Bounding Box) • OBB (Oriented Bounding Box)
Movement Bounds • Question #2: Could A and B have collided during the frame? • Better than Question #1 (solves tunneling!), but...
Movement Bounds • Question #2: Could A and B have collided during the frame? • Better than Question #1 (solves tunneling!), but... • ...even if the answer is “yes”, we still don’t know for sure (false positive).
Movement Bounds • Conclusion • Good: They prevent tunneling! (i.e. no false negatives) • Bad: They don’t actually tell us whether A and B collided (still have false positives). • Good: They can be used as a cheap, effective early rejection test.
Swept Shapes • Swept disc / sphere (n-sphere): capsule
Swept Shapes • Swept disc / sphere (n-sphere): capsule • Swept AABB: convexpolytope (polygon in 2d, polyhedron in 3d)
Swept Shapes • Swept disc / sphere (n-sphere): capsule • Swept AABB: convex polytope (polygon in 2d, polyhedron in 3d) • Swept triangle / tetrahedron (simplex): convex polytope
Swept Shapes • Swept disc / sphere (n-sphere): capsule • Swept AABB: convex polytope (polygon in 2d, polyhedron in 3d) • Swept triangle / tetrahedron (simplex): convex polytope • Swept polytope: convexpolytope
Swept Shapes (cont’d) • Like movement bounds, only with a perfect fit!
Swept Shapes (cont’d) • Like movement bounds, only with a perfect fit! • Still no false negatives (tunneling).
Swept Shapes (cont’d) • Like movement bounds, only with a perfect fit! • Still no false negatives (tunneling). • Finally, no false positives, either!
Swept Shapes (cont’d) • Like movement bounds, only with a perfect fit! • Still no false negatives (tunneling). • Finally, no false positives, either! • No, wait, nevermind. Still have ‘em. Rats.
Swept Shapes (cont’d) • Like movement bounds, only with a perfect fit! • Still no false negatives (tunneling). • Finally, no false positives, either! • No, wait, nevermind. Still have ‘em. Rats.
Swept Shapes (cont’d) • Like movement bounds, only with a perfect fit! • Still no false negatives (tunneling). • Finally, no false positives, either! • No, wait, nevermind. Still have ‘em. Rats.
Swept Shapes (cont’d) • Conclusion • Suck? • Can be used as early rejection test, but... • ...movement bounds are better for that. • If you’re not too picky... • ...they DO solve a large number of nasty problems (especially tunneling) • ...and can serve as a poor man’s continuous collision detection for a basic engine.
Einstein Says... • Coordinate systems are relative
Relative Coordinate Systems • World coordinates
Relative Coordinate Systems • World coordinates • A’s local coordinates
Relative Coordinate Systems • World coordinates • A’s local coordinates • B’s local coordinates
Relative Coordinate Systems • World coordinates • A’s local coordinates • B’s local coordinates • Many others (e.g. origin at point of impact)
Relative Coordinate Systems (cont’d) • Ball vs. world...
Relative Coordinate Systems (cont’d) • Ball vs. world... • in world coordinates
Relative Coordinate Systems (cont’d) • Ball vs. world... • in world coordinates • x component • y component
Relative Coordinate Systems (cont’d) • Ball vs. world... • in world coordinates • x component • y component • in impact coordinates
Relative Coordinate Systems (cont’d) • Ball vs. world... • in world coordinates • x component • y component • in impact coordinates • parallel component • perpendicular component
Relative Coordinate Systems (cont’d) • Ball vs. world... • in world coordinates • x component • y component • in impact coordinates • parallel component • perpendicular component • Change in motion happens along the perpendicular axis
Relative Coordinate Systems (cont’d) • Ball vs. ball...
Relative Coordinate Systems (cont’d) • Ball vs. ball... • in world coordinates
Relative Coordinate Systems (cont’d) • Ball vs. ball... • in world coordinates • x component • y component
Relative Coordinate Systems (cont’d) • Ball vs. ball... • in world coordinates • x component • y component • in impact coordinates
Relative Coordinate Systems (cont’d) • Ball vs. ball... • in world coordinates • x component • y component • in impact coordinates • parallel component • perpendicular component • Energy is exchanged along the perpendicular axis
Relative Coordinate Systems (cont’d) Also, math is often nicer at the origin. x2 - 2xh + h2 + y2 - 2yk + k2 = r2 x2 + y2 = r2
Einstein Says... • Coordinate systems are relative • Motion is relative