Simple flight simulation script and method for Unity

Here’s a very simple flight script that gives Pitch, Yaw, Roll, and two levels of Thrust. I was inspired by a short script called tank.js by Greg Graham, and I simply added some stuff from an old hovercraft script I had modified, and it works pretty decently. I know this is not full-blown flight simulation, but it seems to have the basic functionality.

(see flying-tank3.js, attached)

Here is a link to the demo if you want to try it out - the controls are:
Up - Down arrow keys = Pitch
Left-Right arrow keys = Yaw
z, x = Roll
a, q = Thrust, Thrust x 2

For anyone who wants to see a tutorial on how to create a flying vehicle in 3ds Max and import the model to Unity, setup with a Mesh Collider and the rest, it’s all here:

http://www.3dcognition.com/unity-flight-simulation-tutorial/

A few comments / questions about flight in Unity:

  1. If the flying model hits the ground or another object hard, it can fly in circles crazily all by itself - I wonder if there is a way to tell it in code to reset - I can just let the vehicle fall to the ground and eventually everything is okay again, still, I’d like to understand this situation better.

  2. Back when I used to do this kind of thing in Director, I had a script that controlled how far the camera was from the ship, which gave it a more “flight-like” feel. Has anyone seen such an animal that would work in Unity / js?

  3. What do you guys think? What am I missing here? Are there better ways to do this?

/Brad Strong
3dcognition.com

1184408–46024–$flying-tank3.js (811 Bytes)

I’ve taken this script a bit further as well as added some unity-based functionality - see some of that here: http://www.3dcognition.com/unity-flight-simulator-phase-2/

Also I’m hosting a Flight Simulation / Flight Game contest here: http://www.3dcognition.com/unity-flight-simulator-contest/

If you don’t press the thrust, the plane stops in mid air and falls down slowly. It doesn’t continue moving correctly.

If you are still developing this and in need of some aircraft that are designed around being ultra efficient (allowing for mobile use).