Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. We're looking for your feedback on the platforms you use and how you use them. Let us know!
    Dismiss Notice
  4. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  6. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  7. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  8. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Unity testproject - a little flightsim

Discussion in 'Made With Unity' started by Tiles, Mar 19, 2010.

  1. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,473


    A testproject to learn Unity. A little flight simulator. I will update it from time to time, and extend it step by step.

    Here a very first somehow working version. You can takeoff, fly around, and land. Graphicswise there is just a mainly flat terrain and my airplane. The zipfile contains the Unity project folder, and a exe version in case you don`t have Unity installed (file is not only here linked ... ).

    Flightsimu Build 18, Zipfile, 10.3 Mb

    http://reinerstilesets.de/flightsimubuild18.zip

    I`m pretty new to Unity scripting. Haven`t really known how to spell Javascript before three weeks. So forgive me the mistakes in the scripts :)

    What`s hopefully not a too big mistake is that the flying is not physicsbased. It is variablebased by design. Gives me more control. And it is easier to learn and to follow. Which was for me the most important point. I may switch to a physics based solution at a later point. But first i want to get as much out of the variable based solution as possible.

    One of my problems at the moment is that the movement of the airplane is not really smooth. It is linear in most actions. This is especially visible when i fly a curve, then change direction to the other side. Airplane flies immediately into the other direction. But it is still tilted to the other.

    I also search for a good tutorial around GUI. I want to implement some instruments. And i need a camera solution that doesn`t switch by 180 degrees when i fly a looping. And and and ...

    For now i have at least a rough flying. Which is good enough for a very first version.

    Suggestions, improvements, comments and critics are very welcome :)

    EDIT 31.3.2010: the release files so far, so that you don`t need to dive into the text below:

    Flightsimu Build 18, Zipfile, 10.3 Mb
    http://www.reinerstilesets.de/downloads//flightsimubuild18.zip

    Flightsimu Build 32, Zipfile, 9.2 Mb
    http://www.reinerstilesets.de/downloads/flightsimubuild32.rar

    Flightsimu Build 49, 9.2 Mb
    http://www.reinerstilesets.de/downloads/flightsimubuild49.rar



    Latest build:
    Flightsimu Build 61, Zipfile, 9.4 Mb
    http://www.reinerstilesets.de/downloads/fligthsimubuild61.rar

    Plus the Joypad fix. This one brings smooth behaviour from the keyboard buttons to the joypadbuttons too:
    http://www.reinerstilesets.de/downloads/joypadfix_build_61.rar

    EDIT 8.12.2012 - fixed the dead links. They leaded to a old domain.
     
    Last edited: Dec 8, 2012
  2. stefmen

    stefmen

    Joined:
    Apr 14, 2009
    Posts:
    779
    Nice arcade feeling and easy to fly,
    what you could add is crashing 8)

    keep it up
     
  3. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,473
    Thanks :)

    Since it is variable based, i have no idea how :D

    But is definitely at my To Do List :)
     
  4. gamenut30111

    gamenut30111

    Joined:
    Nov 7, 2009
    Posts:
    399
    Code (csharp):
    1.  
    2. if(speed > 10){
    3.  if(Physics.Raycast(transfrom.postition, -Vector3.up, 2){
    4.  if(hit.collider == terrain.collider){
    5.  disablecontrols = true;
    6. }
    7. }
    8. }
    This isnt the exact code naturally :) its just a simple piece that i decided to make real quick for ya. you would need to make a disable controls variable and set up a if(disablecontrols = false){ around the rest of your code. Also you can unfreeze the rotations and remove some mass from the plane.
     
  5. gamenut30111

    gamenut30111

    Joined:
    Nov 7, 2009
    Posts:
    399
    also did you mean to put the assets in with the exe
     
  6. sybixsus2

    sybixsus2

    Joined:
    Feb 16, 2009
    Posts:
    943
    I think so...

     
  7. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,473
    Thanks Gamenut :)

    Have a look at the moveairplane code. There already is a gameover variable to turn on or off the code. The very first variable called gameover.

    I fear my current knowledge isn`t big enough to fully understand the rest of your suggestions. Especially the unfreeze the rotations gives me headaches :D

    Keep in mind that i`m still a bloody rookie. But i will have an eye at this, and surely return to it :)

    I am at battling with GUI at the moment. Oh how i wish there would be a tutorial available for that ...

    Well, the assets are in the other folder. The Unity project folder. I wanted to provide both. The project folder so that other users can have a look at the code. And the exe to test it outside Unity. For my flavour there are not enough Unity projects out there where rookies like i can learn from. So this is my little contribution :)

    Or do you mean the flightsimubuild18_Data folder besides the exe? That`s what Unity creates when i click at build. Removing this folder makes the exe not longer work. So i have to include this folder too. Or is there a way to include the datafolder within the exe when building the exe?

    There are of course external exe packers. But i didn`t wanted to bother with that for my testfiles here :)
     
  8. gamenut30111

    gamenut30111

    Joined:
    Nov 7, 2009
    Posts:
    399
  9. gamenut30111

    gamenut30111

    Joined:
    Nov 7, 2009
    Posts:
    399
    the physics.raycast would be anything that is below the plane, but sadly i currently realize that this wouldnt be enough, probably just a on collision enter, set disable controls to true, sorry i have raycast on the brain. Unfreezing the rotation most likely isnt on though, ill take a look at your project, you probably dont have the rotation frozen anyways, so dont worry about that, just decrease the mass, i will look at the code and return with some results hopefully. :)
     
  10. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,473
    Thanks for the link. That`s where i read at the moment. My problem is that my cases aren`t listed there. I have pictures of my instruments. And need the needles to rotate. And to just display a smaller rectangle of the compass for example. I hope that i don`t end in making a picture of every state. Would blow up the game. Gamestudio had functions for that cases :)
     
  11. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,473
    Again a few steps further. And my enthusiasm about Unity has slightly decreased.

    The flying behaviour is more like flying now. Means except those situations where the airplane barges around in an impossible waveform. Or when it starts to shake. A overriding problem somewhere. But i cannot find it.

    What really bugs me is that i cannot retreive the local angle of an object. From 0 to 360. What is to retreive is the Euler Angle. And this one jumps from 0 to 180 and back. Which gives me big problems that i cannot really compensate. This one also stops me from making my horizon instrument. Remember it jumps by 180 degrees ...

    Next nightmare is the GUI system. I don`t get through. Hasn`t stopped me from implementing at least two somehow working instruments though.

    So here the next version of my little flight sim. You can still mainly takeoff, fly around, and land. The zipfile contains again the Unity project folder, and a exe version in case you don`t have Unity installed.

    Flightsimu Build 32, Zipfile, 9.6 Mb
    Link removed, see first post
     
    Last edited by a moderator: May 10, 2011
  12. Harissa

    Harissa

    Joined:
    Nov 13, 2008
    Posts:
    136
    Well done! Looks like you're making good progress.

    I sympathise with you about the GUI system. As far as I can see Unity has implemented an excellent visual editing / access system for 3D graphics and then done the exact opposite for the 2D.

    Still, it should be possible implement your horizon instrument. I made a rotating compass for a boat simulation.

    The guts of the Compass code is below

    Code (csharp):
    1. function OnGUI () {
    2. GUIUtility.RotateAroundPivot(boatTransform.rotation.eulerAngles.y, Vector2(needleRect.x+(needle.width/2),needleRect.y+(needle.height/2)));
    3.  
    4.  GUI.Label(needleRect,needle);  //draw Gui element
    5.  
    6.  
    7. }
    You'll need to look at the GUI scripting help to understand what's going on.
    I did experience the 180 degree thing you mentioned but this still seems to work...
    BTW as this is a compass it reacts to the horizontal plane rather then the vertical which you'll need for the horizon instrument.

    No idea how to mask the graphics behind the other instruments and would be interested to know from others how its possible.

    Keep trying, Unity can do pretty much anything you want but some things are much harder than others.
     
  13. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,473
    Thanks for the code snippet. This will surely be useful somewhere :)

    Yes, some things are indeed harder. GUI is one of them. Let`s have a look how to work around them. Maybe this issue even disappears with Unity 3 ;)

    Meanwhile, for just showing a part of the graphics, as needed for the compass and the horizon, i`ve seen a slider example somewhere in the gui code. Maybe that`s of use here too. We will see. At the moment i battle with the flight behaviour :)
     
  14. coin-god

    coin-god

    Joined:
    Jan 21, 2010
    Posts:
    325
    I love it from the pics dude. Im downloading to test it.

    --
    Yes, awesome work so far. :D
     
  15. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,473


    Here comes version three. Build 49, 9.2 Mb

    Link removed, see first post

    Dive flying fixed. Salto forward gets completely blocked now. Only salto backwards works. Overiding problem with shaking fixed. Flight behaviour is finally exactly how i wanted it :)

    To layer the compass and horizon instrument was a very special chapter. And i still need to fix some texture stuff because Unity makes a padding around my textures by default. Which scales the textures, and moves them a bit out of position. But the instruments works as thougth.

    Except the horizon instrument. The euler angle flip ruins it when flying a salto. I can just retreive the euler angles from an object, and not the real angles. I have no idea how to fix this issue. That`s a real drawback compared to 3DGS.

    You can crash now when you collide with a mountain or land in a wrong manner. Crash is relative here though. I reset the position of the airplaine back to initial position and rotation in this case. Game over.

    And i`ve fixed some small stuff plus added other stuff here and there. Like wrap around the playfield so that you cannot fly underneath the landscape anymore.

    Further roadmap:

    - Fix the joypad input settings so that i have the same flight behaviour than with the keyboard
    - The mentioned texture fix
    - put everything debug into a separate file. This stuff is curently scattered over the instrument scripts
    - I need a better solution for the horizon instrument
    - Camera. It is still the standard smooth follow camera
    - Physical crash when possible. No breaktdown of the airplane, but a bounce for example ...
    - And all the little things to fix and to add when i stumble across them :)

    Somebody an idea how to fix the horizon instrument?
     
    Last edited by a moderator: May 10, 2011
  16. RaverGames

    RaverGames

    Joined:
    Mar 21, 2010
    Posts:
    19
    wow very nice

    love it very easy flying

    nice plain Model...

    und auch schön einen deutschen Unity

    User zu sehen ;)

    Move So On!!

    MFG RaverGames
     
  17. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,473
    Mach ich doch glatt ;)

    Glad you like it :)
     
  18. Fracont

    Fracont

    Joined:
    Mar 31, 2010
    Posts:
    12
    For the camera tilt problem, I have changed the last line in the SmoothFollow script:

    // Always look at the target
    transform.LookAt (target, target.TransformDirection(Vector3.up));

    There is still something strange when the airplane is vertical, but it works...

    I think the Horizon tilts in the wrong way (left right inverted), so "tilt = moveairplane.rotationz;" in GuiHorizon could be ok.
     
  19. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,473
    Haha, you`re right, horizon goes into the wrong direction. Haven`t noticed that before :D

    Thanks for that hint. And thanks for the camera fix. That`s definitely better :)

    I need to have a closer look at it anyways I think this odd camera behaviour is also connected to my eulerangle problem with the horizon. The moment the camera jumps a bit is the moment where the eulerangles flips. I don`t really get it that there is no way to retreive the full, not flipping, local angle in Unity. That is a must have in my opinion :)

    Have started some experiments to convert the euler angles to full angles by using three dummy objects now. Let`s have a look how far i can push it :)
     
  20. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,473
    I cannot get the horizon instrument to work proper. My problem is still the Euler Angles. I need Local angles. The try to convert Euler Angles to Local angles turned out to be impossible with Unity.

    The try to catch the angles by variables failed too. That`s this try here.

    As told, using Euler Angles fails too. They flip.

    And that was it. Running out of options.

    In case somebody wants to play around with it, here the file. Maybe somebody of you finds a solution here. 5MB:

    Link removed, see first post

    What i did was to introduce two more variables to catch the movement with. I`ve added localrotationx and localrotationz everywhere where i manipulate my object, the airplane. Still, at the latest after the second looping nothing fits anymore. The variables counts different than my movement code. And i don`t get it why. I fear i`m lost with my horizon instrument without further help :)
     
    Last edited by a moderator: May 10, 2011
  21. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,430
    Just tried out your project, nice little sim.
     
  22. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,473
    Thanks :)

    Maybe you could have a look at the horizon problem? :D
     
  23. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,473


    Here comes the fourth and last version. Build 61 comes with some last final changings

    - Performed the mentioned texturefix at the GUI textures
    - Debugvalues are in a separate file now
    - Added two other cameras, and a way to choose between them. The one camerascript is from Unitywiki
    - Added physical crash. Airplane is not breaking, but it bounces now.
    - Added a way to drive across hills.
    - And some minor changings here and there.

    I wanted to fix the joypad input too, and i wanted to fix the horizon instrument. But my knowledge is simply still too small for that. Maybe when somebody of you shows some mercy ... feel free to change the files in the way you want :)

    There is still lots of finetuning missing. And it is of course buggy. But it was not my goal to create a game, i wanted to learn something. And i have arrived where i wanted to go. The project has fulfilled its purpose. I`ve learned the basics. At least somehow :)

    So that`s it for now. This project is done. Have fun with the result. Maybe it is of use for some of you.

    Finally, many thanks to all of you who has helped me with my first steps in Unity. I hope i can pay the help back at one point :)

    The zipfile contains the Unity project folder, and a exe version in case you don`t have Unity installed. You can takeoff, fly around, and land.

    Flightsimu Build 61, Zipfile, 9.4 Mb
    Link removed, see first post
     
    Last edited by a moderator: May 10, 2011
  24. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,430
    The link doesn't work, perhaps you've misspelled the file?

    If you're talking about using a "top hat" control, then this can be set up in the input manager. Even though the controls are buttons, they need to be set up like an analog joystick. Search for "top hat" in the forums here, I started a thread on the topic a long while back.

    If it's something else that isn't supported by Unity, then google for the free app "AutoHotKey". It's a cool little app that allows you to remap joystick keys to keyboard keys and visa versa.

    I haven't had a chance to look at your code yet, perhaps you can post a snippet of the code you're using? I created something like this a while back using GUIUtility.RotateAroundPivot, is that how you're doing it?
     
  25. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,473
    Ah, thanks for the hint. Was a typoe, link should work now :)

    Nope, it`s about this issue here: http://forum.unity3d.com/viewtopic.php?t=47273&highlight=

    Keyboard has smoothed input, Joypad not. And i cannot get the advice to work :)

    Full commented code is in the project file. GUIHorizon.js .The code itself works, that`s not the problem:
    Code (csharp):
    1. var  mainskin : GUISkin;
    2.  
    3. var bgImage : Texture2D;
    4. var fgImage : Texture2D;
    5. var pitch = 0;  // rotation around X
    6. var tilt:float=0.0; // rotation around Z
    7.  
    8. function OnGUI () {
    9.  
    10.     GUI.skin =  mainskin;
    11.  
    12.     if (moveairplane.rotationx < 180) pitch = -210-moveairplane.rotationx;
    13.     else pitch = -210-moveairplane.rotationx+360;
    14.  
    15.     tilt=moveairplane.rotationz;
    16.  
    17.     GUI.BeginGroup (Rect ( Screen.width/2-304, Screen.height-144, 128, 128 ));
    18.  
    19.  
    20.     GUI.BeginGroup (Rect (22,19,84,92));
    21.  
    22.  
    23.     //---------------------------------------------------------
    24.     //Here comes the rotation
    25.     var matrixBackup:Matrix4x4  = GUI.matrix;
    26.  
    27.     var pos:Vector2 = Vector2(42,45); // rotatepoint in texture.
    28.    
    29.     GUIUtility.RotateAroundPivot(tilt, pos);
    30.  
    31.     var thisRect:Rect = Rect(0,pitch,84,512); //x position, y position, size x, size y
    32.  
    33.     GUI.DrawTexture(thisRect, fgImage,ScaleMode.ScaleToFit);
    34.     GUI.matrix = matrixBackup;
    35.     GUI.EndGroup ();
    36.     GUI.Label (Rect (0,0,128,128), bgImage);
    37.     GUI.EndGroup ();
    38.    
    39. }
    My problem is that i rely at the Euler angles of my airplane. They flip when i fly a salto. And so does my instrument. What i would need is local angles instead Euler angles. I was adviced to use Vector3 for that at one point. But i am totally lost how. My knowledge is too weak. It`s a bit more than six weeks now that i first touched Javascript :)
     
  26. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,473
    That one was a little challenge again, heh. But i got it finally managed. Here the moveairplane script version with smooth joypad arrow buttons. In this scriptversion the joypad arrows behaves the same way than the keyboard. Finally :)

    It`s just the moveairplane.js script in the zipfile. No need to reupload the whole package. Just replace the script. Gives you also a way to check the differences between the two script versions.

    Have fun :)

    Remains the Horizon Instrument issue :)
     
  27. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,430
    Ok, I see what you're talking about. I also looked at my "hacked" artificial horizon and it looks like what I created (a long time ago) suffers from the same issue. :( So I'm not sure I can help code wise... But I was wondering, would it be possible to change the gui texture when the pitch > 90 degrees? Might work.
     
  28. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,473
    Thanks for your input bigkahuna :)

    Yeah, this euler problem is a tough one. It`s not only my horizon instrument that suffers from it. Watch the camera 1. Same issue :)

    The 90 degree idea unfortunately fails. It flips by 180 degrees when it flips. And there is no way to find out if the euler angle is at its normal state or if it is at its flipped state.

    I heard about a vector3 method. To compare the vectors between a static object and the rotated one. But that is ways over my current knowledge.
     
  29. Fracont

    Fracont

    Joined:
    Mar 31, 2010
    Posts:
    12
    Try this!

    The rotation angles now are ok... but there is still something strange (i.e.: GuiHorizon it's ok at 0 degrees, but degenerates a bit around 180)

    I used the Tinus function AngleSigned from this thread:

    http://forum.unity3d.com/viewtopic.php?t=46956&highlight=track

    Code (csharp):
    1.  
    2.  
    3.     static var rotationX: float;
    4.     static var rotationY: float;
    5.     static var rotationZ: float;
    6.  
    7.    function Update ()
    8.     {
    9.         // pitch from 0 to 180, positive above horizon, negative below
    10.         rotationX = GetPitch(transform.rotation);
    11.         // from 0 to 360
    12.         rotationY = GetYaw360(transform.rotation);
    13.         rotationZ = GetRoll360(transform.rotation);
    14.     }
    15.    
    16.     static function GetPitch(rotation:Quaternion)
    17.     {
    18.         return AngleSigned( Vector3.up, rotation * Vector3.up, rotation * Vector3.left);
    19.     }
    20.    
    21.     static function GetYaw(rotation:Quaternion)
    22.     {
    23.         return AngleSigned( Vector3.left, rotation * Vector3.left, rotation * Vector3.up);
    24.     }
    25.    
    26.         static function GetRoll(rotation:Quaternion)
    27.     {
    28.         return AngleSigned( Vector3.up, rotation * Vector3.up, rotation * Vector3.forward);
    29.     }
    30.    
    31.         static function GetPitch360(rotation:Quaternion)
    32.     {
    33.         var rot = GetPitch(rotation);
    34.         if (rot < 0) rot += 360;
    35.         return rot;
    36.     }
    37.    
    38.         static function GetYaw360(rotation:Quaternion)
    39.     {
    40.         var rot = GetYaw(rotation);
    41.         if (rot < 0) rot += 360;
    42.         return rot;
    43.     }
    44.    
    45.         static function GetRoll360(rotation:Quaternion)
    46.     {
    47.         var rot = GetRoll(rotation);
    48.         if (rot < 0) rot += 360;
    49.         return rot;
    50.     }
    51.    
    52.     static function AngleSigned(v1:Vector3, v2:Vector3, n:Vector3)
    53.     {
    54.         return Mathf.Atan2(
    55.             Vector3.Dot(n, Vector3.Cross(v1, v2)),
    56.             Vector3.Dot(v1, v2)
    57.             ) * Mathf.Rad2Deg;
    58.     }
    59.  
    60.  
     
  30. Fracont

    Fracont

    Joined:
    Mar 31, 2010
    Posts:
    12
    The code above does'nt works (there is still interaction between X,Z axis).

    This works, with no interaction:

    Code (csharp):
    1.  
    2.  
    3.     var rotationX: float;
    4.     var rotationY: float;
    5.     var rotationZ: float;
    6.  
    7.     function Update ()
    8.     {
    9.         // pitch from 0 to 90, positive above horizon, negative below
    10.         rotationX = GetPitch(transform.rotation);
    11.         // heading from 0 to 360
    12.         rotationY = GetYaw360(transform.rotation);
    13.         // roll from 0 to 90, positive left, negative right
    14.         rotationZ = GetRoll(transform.rotation);
    15.     }
    16.    
    17.     static function GetPitch(rotation:Quaternion)
    18.     {
    19.         var dir = rotation * Vector3.forward;
    20.         var angle = Mathf.Atan2(dir.y, Vector2(dir.x,dir.z).magnitude);
    21.         return angle * Mathf.Rad2Deg;
    22.     }
    23.    
    24.     static function GetYaw(rotation:Quaternion)
    25.     {
    26.         var dir = rotation * Vector3.forward;
    27.         var angle = Mathf.Atan2(dir.x, dir.z);
    28.         return angle * Mathf.Rad2Deg;
    29.     }
    30.    
    31.     static function GetRoll(rotation:Quaternion)
    32.     {
    33.         var dir = rotation * Vector3.left;
    34.         var angle = Mathf.Atan2(dir.y, Vector2(dir.x,dir.z).magnitude);
    35.         return angle * Mathf.Rad2Deg;
    36.     }
    37.    
    38.     static function GetYaw360(rotation:Quaternion)
    39.     {
    40.         var rot = GetYaw(rotation);
    41.         if (rot < 0) rot += 360;
    42.         return rot;
    43.     }
    44.    
    45.  
     
  31. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,473
  32. coin-god

    coin-god

    Joined:
    Jan 21, 2010
    Posts:
    325
    You should add the posibility to do rolls in the air.

    And maybe a bit of inertia, would add realism :p
     
  33. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,473
    Thanks coin-god :)

    Problem is, for me it does what it should. I don`t want rolls. And inertia would mean to use physics. Which is the opposite of what i wanted to achieve here.

    But feel free to modify the file in the way you want. That`s why the whole source is included :)
     
  34. Frednaar

    Frednaar

    Joined:
    Apr 18, 2010
    Posts:
    147
    Regarding rotation angles, maybe you should switch to a rotation matrix, this is what I used for my helicopter physics engine for fsx http://www.hovercontrol.com/artman/publish/article_110.shtml

    euler angles do not work above certain angles (if i remember > pi/2)

    I can send you the function in c# if you think this helps you
    bye
    Fred
     
  35. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,473
    Thanks frednaar :)

    A Rotationmatrix sounds like another very valid route to go. Unfortunately such stuff is still miles above my head when it comes to the needed knowledge, heh. But feel free to modify the original files in the way you want :)
     
  36. U2

    U2

    Joined:
    Aug 12, 2008
    Posts:
    215
    Hey this is wonderful!

    I took a look at your horizon problem and if I'm not mistaken I think it's a really easy fix.

    in GUIHorizon.js
    Line #47

    Replace:
    Code (csharp):
    1.  
    2.     GUIUtility.RotateAroundPivot(tilt, pos);
    3.  
    With:
    Code (csharp):
    1.  
    2.     GUIUtility.RotateAroundPivot(-tilt, pos);
    3.  
    Seemed to look correct after I made that change even when I did some flips etc..
     
  37. MrRudak

    MrRudak

    Joined:
    Oct 17, 2010
    Posts:
    159
    cool men
    thanks looking forward to your next projects
     
  38. caldepen

    caldepen

    Guest

    This has been great! However, has anyone else noticed the problem seemingly created by the convex mesh collider put on the default mesh? If you crash once the plane acts sporadically (Not banking on turns and sometimes shaking quite violently). It does not seem consistent either, not doing it everytime. If I uncheck the convex box it stops all that but now lands and sinks into the ground a bit, eventually falling through. Still playing around with it a fair bit so might stumble upon something.
     
  39. Mixali4

    Mixali4

    Joined:
    Dec 8, 2010
    Posts:
    1
    woow ! nice job ! i realy likeit !! U have to keep it up !
     
  40. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,473
    The shake is the battle between the pysics engine and the fact that i move the object by values. I never came around that one, sorry. The solution would probably be to move the airplane by forces instead values. But this means less control.
     
  41. jbarrett98121

    jbarrett98121

    Joined:
    Jan 3, 2011
    Posts:
    251
    how would i go about adding a bomb to drop from the plane uppon pressing the spacebar?
     
  42. Alexa999

    Alexa999

    Joined:
    Apr 19, 2010
    Posts:
    52
    You can add this to the cube A BOMB Here is the script

    //Add a Bomb
    var bomb : Transform;

    function Update() {
    if(Input.GetKeyDown("t")) {
    bomb.parent = null;
    bomb.rigidbody.isKinematic = false;
    bomb.rigidbody.velocity = rigidbody.velocity;
    }
    }

    function FixedUpdate () {
    rigidbody.AddForce(Vector3.forward);
    }

    Attach this script to Cube on the wheels and attach Sphere to Cube. Attach RigidBody to Cube and click
    "is kinematic" same with Sphere.
     

    Attached Files:

  43. paulygons

    paulygons

    Joined:
    May 6, 2010
    Posts:
    155
    It took me about 30 seconds to add CloudsToy to this. It can bring your computer to it's knees very easily, but it sure looked great!!
     
  44. jocyf

    jocyf

    Joined:
    Jan 30, 2007
    Posts:
    229
    yeah, Cloudstoy is great (i made it) but must be carefull while configuring clouds or you'll get a nicely game at one FPS.
     
  45. cemC

    cemC

    Joined:
    Dec 23, 2010
    Posts:
    214
    Does it any include Physics Component? An example, if we enter the wind area , The plane change its velocity or something like that.
     
  46. Rush-Rage-Games

    Rush-Rage-Games

    Joined:
    Sep 9, 2010
    Posts:
    1,998
    What is the script that make you restart your position when you get to the edge of the terrain, I cant find it anywhere!
     
  47. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,473
    The script is moveairplane.js

    The codepart is called limiting to playfield. The line starts with line number 308.

    Yes, unfortunately. I found no way to get rid of the physics and have colliders the same time. And the airplane is variable controlled, not physics controlled. So sometimes the physics battles with the variables ...
     
    Last edited by a moderator: Feb 4, 2011
  48. cemC

    cemC

    Joined:
    Dec 23, 2010
    Posts:
    214
    thank you very much. i mention that how to behave the plane by affected aerodynamic physics in Unity3D.
     
  49. Rush-Rage-Games

    Rush-Rage-Games

    Joined:
    Sep 9, 2010
    Posts:
    1,998
    My moveairplane.js is only 280 lines, do
    I have a lesser version? (I have build 61.) This is what my code looks like, I just want to disable it.
     
  50. Rush-Rage-Games

    Rush-Rage-Games

    Joined:
    Sep 9, 2010
    Posts:
    1,998
    Code (csharp):
    1. //Unity 2.61
    2. //~ März 2010 - Moveairplane Build 49
    3.  
    4. //~ Flugscript
    5. //~ Flying script
    6.  
    7. //~ Dieses Script ist ein kleiner Flugsimulator. Ihr könnt damit abheben, rumfliegen, und landen. Hängt es an euer Flugzeug an.
    8. //~ Das Flugverhalten ist nicht realistisch. Es ist Variablenbasiert. Vorsicht. Es kann dadurch zu Konflikten mit der Physik kommen.
    9. //~Herauszufinden wie sie zusammenhängenüberlasse ich euch. Ich übernehme keinerlei Support für das Script. Viel Spass damit :)
    10.  
    11. //~ This script is a little flight simulator. You can take off, fly around, and land. Attach it to your airplane
    12. //~ The flight behaviour is non realistic. It is variable based. Attention, this can lead to problems with the physics.
    13. //~I keep it in your hands to find out how everyhing is connected. I don`t give any support for the script. Have fun :)
    14.  
    15. //~ Reiner "Tiles" Prokein
    16. //http://.www.reinerstileset.de
    17.  
    18.  
    19. //#################################################################################
    20. //---------------------------------------------- Variablen || Variabales ---------------------------------------------------------------------------------------------------
    21. //#################################################################################
    22.  
    23. //------------------------------------------------------------------- Blobshadow stuff --------------------------------------------------------------------------------
    24. static var airplaneangley: float=0.0;//Diese Variable geht zum Blob Shadow. || This goes to the blob shadow.
    25. //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    26.  
    27. static var gameover=0;//Flugzeugcode an und abschalten. Game Over || Turn on and off the airplane code. Game over
    28. var crashforce = 0; // Wenn GameOver brauchen wir eine Force um das Flugzeug crashen zu lassen||When gameover we need a force to let the airplane crash
    29.  
    30. //Rotation und Position unseres Flugzeugs. || Rotaton and position of our airplane
    31. static var rotationx=0;
    32. static var rotationy:float =0.0;
    33. static var rotationz:float =0.0;
    34. var positionx: float=0.0;
    35. static var positiony: float=0.0;
    36. var positionz: float=0.0;
    37.  
    38. static var speed:float =0.0;// speed Variable gibt die Geschwindigkeit an || speed variable is the speed
    39. var uplift:float =0.0;// Auftrieb um abzuheben|| Uplift to take off
    40. var pseudogravitation:float=-0.3; //Abtrieb für Geländefahrten|| downlift for driving through landscape
    41.  
    42. var rightleftsoft:float=0.0; //Variable für sanften Kurvenflug || Variable for soft curveflight
    43. var rightleftsoftabs:float=0.0; // Positive rightleftsoft Variable
    44.  
    45. var divesalto:float =0.0; //Blockt den Vorwärtssalto || blocks the forward salto
    46. var diveblocker:float=0.0; //Blockt seitlichenTaumelflug beim Sturzflug || blocks sideways stagger flight while dive
    47.  
    48.  
    49. function Update () {
    50.  
    51. //-------------------------------------------BlobShadow stuff------------------------------------------------------------------------------------------
    52.  
    53.         //Schatten auf gleiche Drehung wie Flugzeug || shadow to the same angle than the airplane
    54.         airplaneangley= transform.eulerAngles.y;
    55.        
    56. //-------------------------------------------------------Game over ------------------------------------------------------------------------    
    57.  
    58.     //Restart when gameover = 2
    59.     //Restart wenn gameover = 2
    60.     if ((gameover==2)  (Input.GetKey ("enter"))||(gameover==2) (Input.GetKey ("return")))   {
    61.     gameover=0;
    62.     rigidbody.useGravity = false;
    63.     transform.position = Vector3(0, 1.67, 0);
    64.     transform.eulerAngles = Vector3(0,0,0);
    65.     }
    66.    
    67.     //Physik Zeug wenn gameover==1
    68.     // Physics stuff when gameover ==1
    69.     if (gameover==1)    {
    70.     rigidbody.AddRelativeForce (0, 0, crashforce);
    71.     gameover=2;
    72.     }
    73.    
    74.         //Restart the level
    75.     if (Input.GetKey("f2")){
    76.         //We need to manually reset all important static values too. They are global, and keep their values across the levels
    77.         //Wir müssen alle wichtigen static Values zurücksetzen. Sie sind global, und behalten ihre Werte über die Level bei
    78.         speed=0;
    79.         gameover=0;
    80.         rigidbody.useGravity = false;
    81.         Application.LoadLevel(0);
    82.         }
    83.    
    84. //------------------------#####     Maincode fliegen || Maincode flying      #####--------------------------------------------------------
    85.    
    86.     // Mit gameover 0 ist der Code aktiv || Code is active when gameover = 0
    87.     if(gameover==0){
    88.  
    89.         //Variablen auf Position und Rotation des Objekts einstellen || Turn variables to rotation and position of the object
    90.         rotationx=transform.eulerAngles.x;
    91.         rotationy=transform.eulerAngles.y;
    92.         rotationz=transform.eulerAngles.z;
    93.         positionx=transform.position.x;
    94.         positiony=transform.position.y;
    95.         positionz=transform.position.z;
    96.  
    97.     //------------------------- Drehungen des Flugzeugs / Rotations of the airplane -------------------------------------------------------------------------
    98.    
    99.     //Hoch Runter, limitiert auf eine Minimalgeschwindigkeit || Up Down, limited to a minimum speed
    100.     //Hoch Runter, limitiert auf eine Minimalgeschwindigkeit || Up Down, limited to a minimum speed
    101.         if ((Input.GetAxis("Vertical")<=0)((speed>595))) {
    102.             transform.Rotate((Input.GetAxis("Vertical")*Time.deltaTime*80),0,0);
    103.         }
    104.         //Spezialfall sturzflug über 90 grad || Special case dive above 90 degrees
    105.         if ((Input.GetAxis("Vertical")>0)((speed>595))){
    106.             transform.Rotate((0.8-divesalto)*(Input.GetAxis("Vertical")*Time.deltaTime*80),0,0);
    107.         }
    108.        
    109.     //Rechts Links am boden|| Left Right at the ground 
    110.         if (groundtrigger.triggered==1) transform.Rotate(0,Input.GetAxis("Horizontal")*Time.deltaTime*30,0,Space.World);
    111.     //Rechts Links in der luft|| Left Right in the air
    112.         if (groundtrigger.triggered==0) transform.Rotate(0,Time.deltaTime*100*rightleftsoft,0,Space.World);
    113.        
    114.     //Seitenneigung. Mal Minus 1 um in die richtige Richtung zu drehen || Tilt multiplied with minus 1 to go into the right direction  
    115.     //Seitenneigung nur in der Luft || Tilt just in the air
    116.         if ((groundtrigger.triggered==0)) transform.Rotate(0,0,Time.deltaTime*100*(1.0-rightleftsoftabs-diveblocker)*Input.GetAxis("Horizontal")*-1.0);        
    117.  
    118.     //------------------------------------------------ Neigungskalkulationen / Pitch and Tilt calculations ------------------------------------------
    119.         //variable rightleftsoft + rightleftsoftabs
    120.        
    121.         //Soft rotation calculation -----This prevents the airplaine to fly to the left while it is still tilted to the right
    122.         //Soft rotation Kalkulation  ----Dies verhindert dass das Flugzeug nach links fliegt während es noch nach Rechts geneigt ist
    123.         if ((Input.GetAxis ("Horizontal")<=0)(rotationz >0)(rotationz <90)) rightleftsoft=rotationz*2.2/100*-1;//linksrum || to the left
    124.         if ((Input.GetAxis ("Horizontal")>=0)(rotationz >270)) rightleftsoft=(7.92-rotationz*2.2/100);//rechtsrum ||to the right
    125.        
    126.         //rightleftsoft limitieren sodass der Switch nicht zu hart ist wenn man auf dem Kopf fliegt.
    127.         //Limit rightleftsoft so that the switch isn`t too hard when flying overhead
    128.         if (rightleftsoft>1) rightleftsoft =1;
    129.         if (rightleftsoft<-1) rightleftsoft =-1;
    130.        
    131.         //Präzisionsproblem rightleftsoft auf Null || Precisionproblem rightleftsoft to zero
    132.         if ((rightleftsoft>-0.01)  (rightleftsoft<0.01)) rightleftsoft=0;
    133.        
    134.         //Ergibt positive rightleftsoft Variable || Retreives positive rightleftsoft variable
    135.         rightleftsoftabs=Mathf.Abs(rightleftsoft);