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:
-
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.
-
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?
-
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)