5 ms·
It's one thing to create a physics engine which deals with a few balls. But it's black magic to bring if from there to a proper game-ready physics engine which
by OneGuy123 6y ago
It's one thing to create a physics engine which deals with a few balls.
But it's black magic to bring if from there to a proper game-ready physics engine which can handle 30 stacked boxes and complex penetration problems.
There is a reason that there are very few physics engines compared to game engines.
- nineteen999 6y agoIndeed, and physics engines in games often have to deal with capsules, convex hulls and per-poly collision as well, not just spheres, planes and boxes. Not to discount the effort involved here though; it's pretty impressive, I know I couldn't write this without a lot of mental effort.
- Animats 6y agoCollision detection is well understood now, and quite fast for any convex shape. Look up "GJK algorithm". It's collision response that's hard.
- sgillen 6y agoWell understood but still very complex to implement well I think. Most of the novel physics engine type things I see in the robotics space use bullet under the hood for detection, even as they implement their own constrain solver / whatever else.
- Animats 6y agoHis engine is doing a pretty good job. I looked at the code and can't figure out how he gets stable multipoint contact for the pile of balls out of that. There's no linear complementary problem solver. There's no elaborate integrator. Yet it's resolving problems where balls are in contact with many other balls, and where many balls are constrained in multiple directions. Naive approaches to that usually go "sprong" and send something flying. Maybe it's just using a really tiny physics time step. That allows forces to propagate through the whole pile over many time steps.
- johndough 6y agoThe trick is to only apply positive impulses and discard negative ones: https://github.com/IainWinter/IwEngine/blob/6f94a946a90db989412ff29320a0baeca7a5f8cb/IwEngine/src/physics/Dynamics/ImpulseSolver.cpp#L26 https://github.com/IainWinter/IwEngine/blob/6f94a946a90db989... Things will sort themselves out over several frames. Objects might sink into each other a bit, but that is generally not very noticeable unless you make huge piles of spheres. However, it might quickly become a problem in 2D, since you only need a quadratic number of objects to get a "critical" pile, compared to a cubic number of spheres in 3D.
- IainWinter 6y agoThat makes it so nothing explodes, and then there is a second solver that does a small raw position correction after. So it's not lifelike realism, but it works to stop objects sinking into each other too much. There is still a small error though, I'd have to look into more iterations and all that.
- DayDollar 6y agoDont forget that game-engines in addition to "realism" have to handle hollywood physics required of them. Doors shall open with a bang, and then remain open.. Which adds energy to a system, that if it gets pumped into a ragdoll corpse, leads to funny reanimations..
- IainWinter 6y agoOne day... Once I understand what the hell a jacobian matrix is. I do want that stack of boxes :)
- beaumayns 6y agoI had to figure this out recently, a couple things that really helped me are Erin Catto's GDC lectures (particularly [1]) and Allen Chou's game physics articles [2]. I think of a Jacobian as a way to transform the velocities from however they're stored for the interacting objects into linear world-space velocities. For example, in 2D rigid body physics, rotational velocity is usually just a single number representing how fast something is spinning. Given a radius from the center of a spinning object (e.g. object origin -> a contact point in world space), the instantaneous linear velocity is the rotation speed times the tangent to that radius. Therefore, the Jacobian is just that tangent vector - multiplication by that vector transforms scalar rotational velocities into 2D linear velocities. The Jacobian for the object's linear velocity is just the identity matrix. The rotation Jacobian is more complicated in 3D and 4D, but the principal is the same - find a matrix (at a particular point, usually the contact point or the joint location) to multiply with whatever represents rotational velocity to get the linear velocity. [1]https://box2d.org/files/ErinCatto_ModelingAndSolvingConstraints_GDC2009.pdf https://box2d.org/files/ErinCatto_ModelingAndSolvingConstrai... [2]http://allenchou.net/2013/12/game-physics-constraints-sequential-impulse/ http://allenchou.net/2013/12/game-physics-constraints-sequen...