Search Unity

Flight Sim Starter Script (Files Included)

Discussion in 'Made With Unity' started by Mirage, Mar 3, 2010.

  1. Mirage

    Mirage

    Joined:
    Jan 13, 2010
    Posts:
    230
    Here is a flight sim script I recieved several requests for. It has'nt been pretied up and is mostly bare-bones script. All the variables are exposed in the inspector, and have all been given descriptive names to help with the tweaking process. Due to time constraints I have set the initial values to a basic flight pattern, not too realistic, but passable. The first thing you will notice is the lack of collisions, try as I might I could not get them to work, however I'm sure someone here will be able to figure it out and post a fix for it. This is not exactialy a finished project, I have yet to add decent gravity and nosedive, but enough is there to get you started.

    The intent of this script is to help up-and-comming unity students with a basic flight system and HUD componants. No fancy models or terrain here, I am by no means an artist.

    Controls are configured for a joystick, but I'm sure they can be changed to work with IPhone, gamepad or Wii (I dont have them to test on, so I cant gurantee anything).

    Controls are as follows:

    Joystick axis - Movement
    Joystick button 1 - BB Gun
    Joystick button 2 - Airbrake
    Joystick button 3 - Afterburner

    No royalties attached, but if you expand on it and make something better, please post it and pm me, I would love to see what you did with it :D .

    *Note that the model is not mine, I got it off TurboSquid.

    EDIT:
    If anyone knows what I am missing in the upload, please tell me. The html loads ok, but the unity3d file doesn't show up... It is currently uploaded to mediafire untill I can get it hosted to the forum.

    Package File
    http://www.mediafire.com/?mjyydadz41m

    HTML File
    http://www.mediafire.com/?im52zzjzfnn

    .unity3d File
    http://www.mediafire.com/?h2gtijmvnmt
     

    Attached Files:

    REV-FX likes this.
  2. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Usually the best way to post a webplayer in a forum post is to either host the HTML + U3D file on a webserver or zip both together as a download.

    I gave the webplayer a bit of a spin. As you say, this would make a good starting point for many folks wanting to develop a space or other type of flight sim. Thanks for sharing.
     
  3. ColossalDuck

    ColossalDuck

    Joined:
    Jun 6, 2009
    Posts:
    3,246
    Wow, this is nice of you. Thanks. A future project of me and my brother, is making a flight game in space so this may be of value. If we use this you will be credited for sure :D .
     
  4. GrimWare

    GrimWare

    Joined:
    Jul 23, 2009
    Posts:
    211
    This is a great start for newbies (like me!) starting with Unity.

    Thanks for your contribution.
     
  5. Maurice-Hoffman

    Maurice-Hoffman

    Joined:
    Jan 22, 2009
    Posts:
    182
    Thanx maybe we can make a tutorial out of this for Unityknowledge, is it me or is the model missing from the package ?

    Maurice
     
  6. Essal

    Essal

    Joined:
    Feb 16, 2010
    Posts:
    107
    Dammit. Now I want to make a flight sim..:p haha

    Thanks a million:)
     
  7. CoatlGames

    CoatlGames

    Joined:
    Apr 25, 2008
    Posts:
    773
    yeah, some files are missing, it needs some tweaking to make it work
     
  8. Mirage

    Mirage

    Joined:
    Jan 13, 2010
    Posts:
    230
    :? It is working when I import...

    The only ways I can find to test/play the uploaded version are to either place the html and unity3 files in the same folder and run html, or to compile a webplayer from the project. Sorry I can't get a working link up, but there is no how-to on how to upload here.

    About the model, the mesh seems to have been lost in the upload to mediafire, and I cant find it anymore. Sorry about that, but it was purly a graphics thing. Simply attach any model to the prefab Fighter and it will work fine, no dependencies on the mesh at all.
     
  9. Essal

    Essal

    Joined:
    Feb 16, 2010
    Posts:
    107
    The plane mesh is missing, but I just imported a plane model i had lying around :)

    I really can't thank you enough for this!
    It's really great, and gave me a chance og playing around with making a flight game:)
    (always just love flying around in games, without having a specific purpose) so this makes me able to make my own little casual game..:)
     
  10. Tinus

    Tinus

    Joined:
    Apr 6, 2009
    Posts:
    437
    Nice. :)

    Quick bug report: You actually can collide with the (waypoint-)cubes. This seems to add a torque to the plane that you cannot get rid of by compensating in any way.
     
  11. greenlig

    greenlig

    Joined:
    Mar 12, 2010
    Posts:
    5
    Thanks Mirage for the awesome script. It is exactly what I needed!

    @Tinus - I found the same happened to me. I added a box collider to the Fighter, so it could collide with the terrain. I had the same crazy torque thing happen, until I changed the Angular Drag to 10. That seemed to get rid of the problem for me.

    Greenlig
     
  12. jeroll3d

    jeroll3d

    Joined:
    Nov 6, 2010
    Posts:
    249
    This is my first post here in the community. I'm from Brazil, sorry my bad english. This script is very good, but I use it with the keyboard - no Joystic. I managed to configure it. :)

    But there's a problem, I need the acceleration is variable. I have total control of speed. When I set the speed, I can not control it. When do I stop my object, it returns the floor: (

    I want to have complete control over speed, as there?

    Thanks
     
  13. Mr-Logan

    Mr-Logan

    Joined:
    Apr 13, 2006
    Posts:
    455
    Damn, this is great! been looking for a tutorial on air-plane physics for ages, never looked on the forums though, always just googled xD
     
  14. Stolenbows

    Stolenbows

    Joined:
    Nov 30, 2010
    Posts:
    82
    downloading right now thankyou always liked flying game's and now i can make my own
     
  15. caldepen

    caldepen

    Guest

    I downloaded the package and it auto started Unity and installed all the files in the current project. My fault I know but kind of a silly assumption isn't it? No prompts, nothing... now I have to go through all the files and delete them and reinstall to a new project.

    Not blaming anyone, just venting.

    Hopefully this is awesome. Thank you.

    Edit: The second time I downloaded it to a new project and it did prompt me! I wonder why it did this time but not the first time when it really counted...
     
    Last edited by a moderator: Dec 3, 2010
  16. Knight12ify

    Knight12ify

    Joined:
    May 21, 2010
    Posts:
    520
    It's going to help me a lot, it'll be in the first level of my FPS/Racing game. Say about that, can you configure a flight/racing simulator where you race in the simulator?
     
  17. alexxxhp

    alexxxhp

    Joined:
    Dec 9, 2010
    Posts:
    8
    I am trying to make a space flying with 3rd person perspective view and adding touch joysticks for the controls left joystick left right up and down and right joystick rotate view anyone have any ideas thanks. I have tried everything that comes with unity with no luck.
     
  18. steelersfan252

    steelersfan252

    Joined:
    Dec 23, 2010
    Posts:
    217
    hey i was wondering before i download it if you can get in and out of the aircraft?

    if anyone has the answer e-mail me at timothydude10@aol.com
    if anone knows the scripting to get in and out tell me also
    for example you press (x) to get in and then (x) to get out

    make sure its for the pc thank you
     
  19. Tutanhomon

    Tutanhomon

    Joined:
    Sep 15, 2009
    Posts:
    101
    thanx, pretty nice stuff =)
     
  20. Mirage

    Mirage

    Joined:
    Jan 13, 2010
    Posts:
    230
    Wow, just logged back in to re download this (formatted HD), got a programming course in college here, want to get back into this in my "spare time".


    Pretty sure most of the questions here have either been resolved or the user went on to better things. For the sake of future readers:

    jerrol3d: Acceleration with a keyboard
    Try binding the keystroke to the throttle. Holding down the "accelerate" and "decelerate" keys should then set the throttle which affects the speed. I would avoid binding anything directly to the speed as you loose the acceleration and deceleration sliders. (trying desperately to avoid the obvious question why you would want to play a flight sim without a joystick/gamepad...)

    alexxxhp: Mapping input:
    You are using a gamepad? If so your problem lies in the edit > preferences > input area. I have no experience adding gamepad support (just got my first pc gamepad actually, havnt set it up as input yet). Should be relativly simple, try mapping buttons to print out their values, press every key and see what their input names are.

    steelers fan 252: Getting in and out of aircraft
    Should be as simple as setting a switch that enables or disables the script/ switches between control schemes.

    Apologies to caldepen. As I built the file on my computer I did not extensivly test the actualy project file iteself, just the script. Hope you got it working.
     
  21. Knight12ify

    Knight12ify

    Joined:
    May 21, 2010
    Posts:
    520
    Despite what I said earlier I didn't download it and I don't know what a joystick axis is.
     
  22. hallamasch

    hallamasch

    Joined:
    Nov 29, 2010
    Posts:
    153
    Converted to C#
    Added the original Modell (http://www.psionic3d.co.uk/?page_id=25)

    The Folder Structure changed quite a bit since I copied out of my project folder.
    I wanted todo it now, before I start messing with it.

    It's quite possible that the weapon code is not working at the moment since I already started work on it.
    Then I decided it would be nice to put my C# conversion up here for anybody else so I had to do some undos.

    The Waypoint stuff is not included in this version.

    I will probally be using this as a base/placeholder while trying to get to grisp with Flight Dynamics.
    For anyone interested the nasa has some great explanations in regard to flight dynamics (http://www.grc.nasa.gov/WWW/K-12/airplane/)

    Download Link: http://www.mediafire.com/?b8cubc0u5eua03a


    Any Finally a Big Thank You
     
    Last edited: Mar 1, 2011
  23. Knight12ify

    Knight12ify

    Joined:
    May 21, 2010
    Posts:
    520
    Whats a Joystick Axis?
     
  24. Novodantis

    Novodantis

    Joined:
    Nov 12, 2009
    Posts:
    95
    How'd you mean? If it was a general question, a joystick axis is a range of input along a dimension of the joystick input eg. forward/backward is the joystick Y axis.

    In the context of Unity; if you use GetAxis() instead of just direct input keys (as you really ought to, if your user is to be able to change controls ;) ) then you will find both joystick and keyboard can control something by default.

    This is most likely caused by manipulating an object with rigidbody physics directly rather than with forces, ie. by Rotate() rather than ApplyRelativeTorque(). This would explain why angular drag fixes it, and compensating inputs do not (as Rotate will not affect the angular momentum). Not looked, so I'm making a guess.

    Will definitely take a good look at this later!
     
  25. Knight12ify

    Knight12ify

    Joined:
    May 21, 2010
    Posts:
    520
    I don't get it and I don't think I will get it so just leave the question.
     
  26. Gundark

    Gundark

    Joined:
    Feb 27, 2011
    Posts:
    45
    Joystick Y axis is when you rotate your stick ( generaly using as rudder control ). Not all joysticks have Y axis rotation.

    Knight12ify: Moving joystick frontward/backward is X axis (with this you put nose of airplane up and down), and left/right movement is Z axis ( with this you make your airplane roll). If you still don't get it, then i strongly advise you to try some real flightsim with joystick. Flightgear is free nad opensource, and it is fairly decent.
     
  27. Novodantis

    Novodantis

    Joined:
    Nov 12, 2009
    Posts:
    95
    True, for the aircraft. However, on the joystick, forward/backward is typically the Y axis, and the twist motion is called the Z. In Unity they are called Horizontal and Vertical though, which is less likely to confuse. But I agree, in terms of the movements on an aircraft you are absolutely correct.
     
  28. KillerScript

    KillerScript

    Joined:
    Aug 20, 2010
    Posts:
    368
    I have a problem,
    I can't turn down or left or rolling left...
     
  29. CraigF

    CraigF

    Joined:
    Oct 18, 2010
    Posts:
    16
    Great script! Helps what I am doing quite a bit, one question though:

    I noticed with this script that when you bank, you don't actually change heading. You have to add pitch to change the heading. Is there a specific variable I need to change to enable this or do I have to modify the script another way for this to work?
     
  30. Starship

    Starship

    Joined:
    Jun 28, 2011
    Posts:
    6
    The .unity3d file was removed.
     
  31. Starship

    Starship

    Joined:
    Jun 28, 2011
    Posts:
    6
    The .unity3d file has been removed!
     
  32. Mirage

    Mirage

    Joined:
    Jan 13, 2010
    Posts:
    230
    Wow, I didn't think anyone was still using this. Afraid I've been pretty busy with school and work but I want to get back to working on this again. I am going to start cleaning out the code some and adding more realism and more accurate flight dynamics (been doing some research and I might need to redesign some code). If anyone has suggestions for improvements or additions they would like to see please either add them here or PM me.
     
    Last edited: Jul 6, 2011
  33. tspree15

    tspree15

    Joined:
    Oct 25, 2011
    Posts:
    35
    Has anyone made any revisions?

    I'm a beginner and I'm having lots of trouble.

    I'll gladly pay for some help.

    Thanks
     
  34. forcedrecon

    forcedrecon

    Joined:
    Dec 20, 2011
    Posts:
    2
    can someone help me make this work with iphone
     
  35. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    How do you use unity if you dont know what a joystick axis is? :D
     
  36. crocodile5

    crocodile5

    Joined:
    Sep 12, 2011
    Posts:
    18
    First of all thank you for the great script. I am learning to make a space sim game and the control systems I was using were driving me crazy :). And this just worked greatly.

    I have a question tho, when I use mouse movement input for yaw and pitch the ship seems to be rotating like mad and it only works with either a joystick or sepate keys for each axis but I want to use mouse as well. Is there a way to do it?
     
  37. magarcan

    magarcan

    Joined:
    Sep 25, 2012
    Posts:
    34
    Can anyone upload it again?

    Thanks!!!
     
  38. broesby

    broesby

    Joined:
    Oct 14, 2012
    Posts:
    118
    I love this flight script. It really helps a beginner like me. It is easy to use and figure out.

    I have two questions. One simple and one complicated:

    1) Is there an easy way to limit the "Roll" amount to... let's say 80-90 degrees. In the scene I'm trying to make I don't want users to be able to fly upside down (at least not in an easy way).


    2) I'm trying to make "Upwind" zones where the lift on the "plane" is so high, that the movement of the plane. goes up almost no matter what you do (except actively flying downwards ofc). Like a stong thermal on a paraglider.

    I cannot for the world figure out how :confused::(

    I tried easy ways like changing liftconstant and gravity... not really the desiresd effect. Some change in flight mechanics, but no "real lift".
    I tried entering flyerrigidbody.Addforce / flyer.Addforce with different variables..... No movement at all.

    I tried getting a complicated solution like this: http://forum.unity3d.com/threads/156974-quot-Upwind-Zone-quot
    ... to work.

    It doesn't... even with the help I received from others. I'm afraid I'm simply too dumb and ignorant to understand how :roll:.

    Would a kind soul maybe help me.... Sorry for being a newb.
     
  39. Rabbit

    Rabbit

    Joined:
    Dec 30, 2012
    Posts:
    8
    Thankyou for this package, extremely helpful.
     
  40. omelchor

    omelchor

    Joined:
    Jun 15, 2011
    Posts:
    20
    Any Finally a Big Thank You
     
  41. Meceka

    Meceka

    Joined:
    Dec 23, 2013
    Posts:
    423
    Can you re-upload the unity file please, unity3d file link is broken. Thanks in response.
     
  42. khos85

    khos85

    Joined:
    Jul 21, 2013
    Posts:
    541
    This is a pretty cool thread! I got it all working but when I added a collider to the plane to prevent from going through the ground, now if it hits the ground or does a "taxi" it won't lift off again, any advise would be much appreciated :) why would a collider affect this so much?
     
  43. khos85

    khos85

    Joined:
    Jul 21, 2013
    Posts:
    541
    Dude, is this not it?:
    Package File
    http://www.mediafire.com/?mjyydadz41m