How do you use custom physics (especially friction and aerodynamics) in Unity? (for HPC simulation)

Dear all, I am a research intern working for a high performance computing research group from one of the world’s top university. I would like to know 2 things:

  1. how realistic is the Unity Engine’s physics for simulation of friction and aerodynamics?

  2. how modular is the physics engine? (ie how hard is it to swap it for our custom physics scripts)

My research group is developing a high performance computing system for vehicle physics modelling. This allow one to find better aerodynamic layout for a race car that enhances down force and other desirable aspects.

The problem we have right now is that we are trying to find a better way to demonstrate the results to non technical people. We would like to either buy a Unity car racing game or build one such game by ourselves, and then swap out the physics engine(to something that closely model a real world race car). The idea is to show people that a car with a better aerodynamic layout will perform much better especially around corners.

We would like to know whether the above is possible, if yes how much work is involved. We have lots of experience in physics, high performance computing and super computers, but not much in graphic design or game development. It would be best if we can have a game where all the graphics and game mechanics are done for us, and we only need to tell the car how much traction, drag, acceleration etc.it should have.

You should refer to PhysX SDK - Latest Features & Libraries | NVIDIA Developer and various documentation there for a better overview of the physics engine Unity uses.

I recommend Edy vehicle physics pro which does calculate aerodynamic drag among other things. http://vehiclephysics.com/ (there isn’t anything better).

However if you want to simulate drag over different polygons you will need a far more accurate approach, you should talk to the author @Edy

Thank you very much, I would definitely take a look at these.

@hippocoder , thanks for the mention!

Short answer: friction is not realistic, and aerodynamic physics is not included.

The friction among two solid bodies contacting is implemented as a fast approximation typically enough for gaming, but it doesn’t produce realistic results. This is extracted from the Unity manual:

Please note that the friction model used by the Nvidia PhysX engine is tuned for performance and stability of simulation, and does not necessarily present a close approximation of real-world physics. In particular, contact surfaces which are larger than a single point (such as two boxes resting on each other) will be calculated as having two contact points, and will have friction forces twice as big as they would in real world physics. You may want to multiply your friction coefficients by 0.5 to get more realistic results in such a case.

The components available for vehicular physics (WheelCollider) are worse even for gaming, so they’re not even close to anything we could call realistic.

The good part is that the rigidbody dynamics work pretty good. You may create a rigidbody, apply forces to it, and it will exhibit the expected realistic behavior. Another good point is that the suspension part of the WheelCollider is pretty accurate when used correctly. So we can configure the WheelCollider to work in friction-less mode, calculate the tire forces ourselves, and finally apply them to the vehicle’s rigidbody. That’s is what I’m actually doing in Vehicle Physics Pro (VPP) with highly realistic results.

The same applies for the aerodynamic calculations of the vehicle:

  • The actual velocity of the vehicle (speed + direction) is known with great precision.
  • The aerodynamic forces are calculated. Currently I use a simplified model with separate coefficients for aerodynamic drag and aerodynamic downforce. But any aerodynamics model may be applied here.
  • The resulting aerodynamic forces are applied to the rigidbody at the specified application points. Currently I simulate two aerodynamic components per vehicle, one at the front axle and another at the rear axle. This allows configuring the aerodynamic balance of the vehicle at high speeds easily.

In this video you can observe the aerodynamic load at the Telemetry data (Load column). You can see how the perceived weight goes from 1300-1400 Kg at low speeds to 1800-1900 Kg at the end of the fast straights. This is caused by the aerodynamic downforce:

https://www.youtube.com/watch?v=SdeJcpWNHsw

The physics engine offers various resources that can be used, ignored, or replaced with your own calculations. You may ignore all physics resources and use entirely your own custom physics, as long as you can made it “talk” with unity (i.e. it’s written in C#, or it’s C++ compiled into a DLL compatible with Unity’s native DLL interface).

In the case of VPP I customized the tire friction and aerodynamic forces, which come from C# scripts. Suspension springs, gravity, collisions, and rigidbody friction are still simulated by the Unity physics engine.

The physics engine also offers the Kinematic rigidbody. This is a rigidbody but it won’t react to physics events (collisions, forces). Instead, you define its position, rotation and velocities explicitly. The engine will notify you when this body contacts other physic bodies, so you may react to the collisions. In this case you would have a kind of collision solver, but the physics for the movement of the bodies and the reactions to the collisions would be entirely coded by you.

4 Likes