Porting A Fortran Flight Simulator To Unity3D

There’s an old saying (paraphrasing a quote attributed to Hoare): “I don’t know what language scientists will use in the future, but I know it will be called Fortran.” The truth is, there is a ton of very sophisticated code in Fortran, and if you want to do something more modern, it is often easier to borrow it than to reinvent the wheel. When [Valgriz] picked up a textbook on aircraft simulation, he noted that it had an F-16 simulation in it. In Fortran. The challenge? Port it to Unity3D.

If you have a gamepad, you can try the result. However, the real payoff is the blog posts describing what he did. They go back to 2021, although the most recent was a few months ago, and they cover the entire process in great detail. You can also find the code on GitHub. If you are interested in flight simulation, flying, Fortran, or Unity3D, you’ll want to settle in and read all four posts. That will take some time.

One limitation. The book’s simulator was all about modeling the aerodynamics using data from wind tunnel tests. However, the F-16 is notorious for being a negative stability aircraft — meaning it’s virtually impossible to fly by hand. It is very maneuverable, but only if you let the computer drive using the flight control system. When you direct the aircraft, the control system makes your desire happen, while accounting for all the strange extra motions the plane will create as it flies.

The problem: the book doesn’t include code for the flight controller. [Valgriz], of course, wrote his own. He uses some PID controllers along with limiters for G-force and angle of attack. Interestingly, to do this, the simulator actually runs its own stripped-down simulator to determine the effects of different control inputs.

This is one of those projects we aren’t sure we would attempt, but we’re glad someone did, and we can watch. Just be careful. An interest in flight simulation can lead to reduced space in your garage. We know of at least one F-16, by the way, that has an Arduino in it. However, it is probably the only one.

8 thoughts on “Porting A Fortran Flight Simulator To Unity3D

  1. the F-16 is notorious for being a negative stability aircraft

    As demonstrated by Maciej “Slab” Krakowian during Radom Air Show 2025.
    https://www.youtube.com/watch?v=8UHcO3tfAYw

    Now all that’s left of him is a concrete slab at the cemetery because flying full afterburner into the ground is what made him turn from biology into physics within a 50 miliseconds or so. He did the same kind of industrial stupidity like Stockton Mush from OceanGate.

    1. Agreed. It is a solid engine but it grew into a corporate tool alongside the hobbyists it nurtured into professional game devs.

      If you’re looking for a FOSS game engine, Godot is the current hotness.

  2. The comment in the summary that the source he uses for the F-16 simulation, Aircraft Control and Simulation, by Stevens and Lewis (actually he shows the newer edition so I guess its technically Stevens/Lewis/Johnson, but the F-16 sim is in the earlier editions before Eric Johnson was added as a co-author) doesn’t contain code for the flight controller is strictly true (in that the code listings in the appendix do not contain the controller). However the textbook itself is one of the classics for learning about aircraft controls–the simulation itself is only described in about 1/6th of the text.

    Most of the book provides background and example information for how to design control systems to be applied to the example aircraft model (the F-16 is the highest fidelity example, but there are others also presented to introduce some concepts). While some of the control designs are illustrated through linearized models or block diagrams, there is actual code for several designs sprinkled through out the chapters.

    [Valgriz] did a great job implementing his own controller, but if someone else is interested in building up their own simulation don’t let that be a stumbling block–the book as plenty of guidance on implementing one—and if you just want to get it flying initially, you can just move the CG in the simulation forward to improve the static stability (several of the early exercises in the text do that so the student can get the simulation running before worrying about unstable dynamics).

    FORTRAN shouldn’t be a completely stumbling block either–the book has been around enough that there are several re-implementations of its simulations around the web in various languages.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.