Finding the maths behind Unity's physics

Hi Guys,

I want to see the the calculations that make up Unity’s 3D physics (Excluding collisions). I want to understand exactly what it’s made out of, to see how true to life the calculations are. I know no physics engine is, so I’d like to know what calculations it’s including and excluding.

Particularly I’d love to see the calculations behind drag, angularDrag, and mass. What exactly goes into a rigidbody’s Update, whether I can modify data going in, and how it’s calculated. I want to create some accurate simulations, updating the drag and angular drag by mesh shape, mass, barometric pressure, humidity, air temperature, wind speed, ect.

For my calculations to definitely be correct I need to see every calculation that goes into them. I may possibly just ignore Unity’s physics engine entirely and make all the calculations myself, but it’d be great if I could work into the existing engine, and would love to know more about it anyways.

Is there any source it comes from that I can read about, and how Unity’s implemented/affected it?

Thanks!

3d or 2d?

3d, Unity uses ‘PhysX’:
https://developer.nvidia.com/sites/default/files/akamai/physx/Index.html
I believe they’re on 3.2, maybe 3.3, for Unity 5

The source for which isn’t trivial to get your hands on. You’ll need to sign up as a developer:

2d, Unity uses Box2D:
http://www.box2d.org/documentation.html

The source for which is openly available:
https://github.com/erincatto/Box2D

Unity for the most part wraps around each engine with their own API.

When you dig into the PhysX API you’ll see how the Unity ‘Rigidbody’ design came about… it’s following most of the design structure of PhysX.

I am unsure as to what changes they may have done in the calculations part of it. I highly doubt any. So the actual “maths” of that source can be trusted.

2 Likes

Absolute, legend. Thanks lordofduct :slight_smile:

Unity is on PhysX 3.3 since 5.0.

2 Likes