I am working on a physics application and need to find solutions to systems of linear equations. I know that unity’s default physics has a solver somewhere (you can change its properties in the settings). I was wondering whether it is possible that I could get access to the solver itself somehow and use it in my own scripts instead of having to write my own solver. Would this be possible and is it even a good idea, or is there something about doing that which would be problematic?
Short answer is no, you can’t do that. The default 2D and 3D physics engines in Unity (nVidia PhysX and Box2D, respectively) are in the C++ side of the Unity Engine. You can use them only through the components, methods, and properties exposed in the Unity API.
Still, both engines are available as open source so you may review the code if that helps:
I’m assuming that you are trying to implement an ODE solver to compute rigid body quantities like velocities, angular velocities, position, and quaternions based on previous states and inputs of the system.
The thing is you don’t need to, you just figure out what are ultimately the forces and torques you need to apply using the AddForce() and AddTorque() rigidbody methods. I never come into any issues including additional forces such as quadratic drag and added mass forces in Unity. Just find the forces in the x, y, z directions (body frame), multiply them by transform.up, forward, and right, then sum them and use AddForce(). You do a similar procedure for the torques.
I’m saying this on the basis that you’re referring to rigid body or articulation body physics when you mention physics since Unity allows you to simulate collisions. Physics could mean other things such as thermodynamics, fluid mechanics, and so on. If you’re referring to those, then it’s best to write your own and maybe use InvokeRepeating() to run it at a specified sampling rate or just use Unity as a visual environment and let some other software do the computations.