# Where can I find details on the physics engine?

I have just one question, everything else I write is just to satisfy your curiosity. My question is: How can I find out exactly how Unity evaluates forces, velocity, friction and drag to calculate the next velocity and object position?

I’m having trouble with object movement. The variables at play are drag, friction via PhysicMaterials and using a lot of `rigidbody.AddForce(dir, ForceMode.VelocityChange)`. The biggest problem is that doing this work in the Update loop yields different results for different framerates, but in theory it should not, because logic like this is as simple as it gets:

``````velocity += deltaTime * acceleration
``````

The above is a great example because it’s easy to debug. The problem is that the `velocity` getter is not updated until the `FixedUpdate` loop, so adding several different values to `velocity` will just continually use the old value.

``````rigidbody.velocity += explosionA;
rigidbody.velocity += explosionB;
``````

The above does not yield the expected result, because velocity is precalculated. It comes out to be the same as the following:

``````Vector3 cachedVelocity = rigidbody.velocity;
rigidbody.velocity = cachedVelocity + explosionA;
rigidbody.velocity = cachedVelocity + explosionB;
``````

My bigger problem is that it’s hard to get movement speed and acceleration quite right, since the game is using a mish-mash of built in physics and manual controls to get everything “just right”.

Unity uses the PhysX engine. I don’t think you’ll find a simple one-line “this is how we resolve forces”, but you could try looking at the developer documentation there: http://www.geforce.com/hardware/technology/physx

Physics is a complex topic an a lot variables can’t be predicted (like most collision based stuff). If you want to know how (manual) forces and drag are applied see my answer over here (and the linked one). For information how the bouncing values in your physics material are combined see this question.

However things like friction and complex collisions (which involve angularVelocity as well as linear velocity) are way more complex and can’t be predicted / calculated that easy.

Also you should do everything physics related in FixedUpdate. Update in combination with Time.deltaTime only works for linear equations. Everything more complex can’t be “corrected” with a linear scalar like deltaTime. A quadratic equation “fixed” with deltaTime is almost correct. However the slower your Update runs the larger is the error. Using FixedUpdate ensures at least a contant behaviour since you have a constant framerate.