Implementing drag
08 Mar 2019Drag is almost fully implemented now. It turned out that simulating it in a semi-realistic way isn’t as terribly difficult as I thought, although it’s somewhat convoluted; the drag force is proportional to the reference area multiplied by the dynamic pressure, which in turn is equal to the air density (which isn’t too hard to calculate based on atmosphere model data using the barometric formula) multiplied by the vehicle velocity squared, divided by two. And that’s mostly how I calculate the drag force in my simulation – I simply multiply the reference area and the dynamic pressure with a static drag coefficient.
The only things remaining there are an approximation of the center of pressure, where the drag force acts (it’s also where the lift force acts), and calibrating the drag coefficient so that the strength of the force is realistic, which I will do when I have pretty much everything implemented.
In other news, I had a pretty bad bug where the AddForceAtPosition
RigidBody method, which I use to add the torque generated by gimbaling, would completely mess up the trajectory. I couldn’t figure out what was wrong despite it bothering me for several days, but after trying to use it again today… it just worked. Nice.
Update 2019-03-09: The bug seems to have been caused by the Unity-calculated center of mass being slightly off, which probably is a result of the mesh not being completely symmetric when exported from the CAD software. This is worked around by forcing the X and Z values of the center of mass to zero.