Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Simple flight simulation script and method for Unity

Discussion in 'General Discussion' started by lupo, Mar 7, 2013.

  1. lupo

    lupo

    Joined:
    Apr 4, 2009
    Posts:
    43
    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
     

    Attached Files:

    Last edited: Mar 8, 2013
  2. lupo

    lupo

    Joined:
    Apr 4, 2009
    Posts:
    43
  3. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,605
    If you don't press the thrust, the plane stops in mid air and falls down slowly. It doesn't continue moving correctly.
     
  4. JamesArndt

    JamesArndt

    Unity Technologies

    Joined:
    Dec 1, 2009
    Posts:
    2,913