Search Unity

Helicopter Tutorial

Discussion in 'Community Learning & Teaching' started by maxwelldoggums, Feb 16, 2010.

  1. maxwelldoggums

    maxwelldoggums

    Joined:
    Sep 8, 2008
    Posts:
    157
    Last edited: Aug 15, 2014
  2. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    Thanks a bunch :)
     
  3. perversonality

    perversonality

    Joined:
    Jan 8, 2010
    Posts:
    57
    That's awesome! Thanks for sharing
     
  4. WebWolfRussian

    WebWolfRussian

    Joined:
    Feb 5, 2010
    Posts:
    123
    This is a vary vary cool ))) Maybe you create tutorial how can create Tank (Panzer) how in this video http://www.youtube.com/watch?v=AdsKJFUqWEI
    or how in crysis )))) Caterpillars which react to hummocks))

    The helicopter:
    And can change handle on more simple? For example as in Battlefield Bad Company 2 or how other games?
    Because in this example very difficult keep certain level. the plane on keys W and S should move to top in them and when we will release them should will stop at that level on which have omitted, instead of to continue to rise upwards.

    Sorry for my English )))
     
  5. maxwelldoggums

    maxwelldoggums

    Joined:
    Sep 8, 2008
    Posts:
    157
    The controls can be simplified quite easily if you would like. It might not be very accurate, but try just putting in a line that says

    "rigidbody.velocity *= 0.99"

    in the fixed update function. That might make it slightly easier to control...
     
  6. ColossalDuck

    ColossalDuck

    Joined:
    Jun 6, 2009
    Posts:
    3,246
    Sweetness.
     
  7. Wolf Dreamer

    Wolf Dreamer

    Joined:
    Sep 2, 2009
    Posts:
    142
    horizontal2 and vertical2 are mentioned in the helicopter script, but not defined anywhere.

    I tried importing the helicopter to another project, with all of its assets, but I keep getting an error for horizontal2 and vertical2. I look through all the scripts but it isn't defined anywhere at all.
     
  8. maxwelldoggums

    maxwelldoggums

    Joined:
    Sep 8, 2008
    Posts:
    157
    Oh, I'm sorry. Horizontal2 and Vertical2 are input axes set up in the Input preferences of Unity. Simply go to the Edit menu, then click Project Settings, Input. There you should be able to define the horizontal2 and vertical2 axes.
     
  9. Wolf Dreamer

    Wolf Dreamer

    Joined:
    Sep 2, 2009
    Posts:
    142
    Thank you. I looked through the documentation, searching for horizontal2, and didn't see where it was setup at.
     
  10. DigitalAdam

    DigitalAdam

    Joined:
    Jul 18, 2007
    Posts:
    1,204
    Does your scripts work within Unity 3?

    It keeps crashing Unity every time I load the scene in your project folder. It also crashes Unity if I copy your scripts to a new project, and click the 'Helicopter_Script.js' file like I want to either drag-and-drop or double-click to edit...
     
  11. maxwelldoggums

    maxwelldoggums

    Joined:
    Sep 8, 2008
    Posts:
    157
    Hmm... I'll have to look into that...
     
  12. enyllief

    enyllief

    Joined:
    Oct 17, 2010
    Posts:
    36
    Truly, it's nicely done. A simple tutorial, yet very effective. :)
     
  13. agenda.

    agenda.

    Joined:
    May 8, 2010
    Posts:
    21
    difficult/realistic controls, much like opf and armed assault.
    i like it!

    thx.
     
  14. Whitebear

    Whitebear

    Joined:
    Nov 5, 2009
    Posts:
    2
    A small remark about the 1st picture (a wing profile with air streams above and below). The velocity of the air stream is higher ABOVE and not BELOW the wing as the air stream above has longer way to flow due to a special wing profile. This causes a pressure difference. Becuse of higher air stream speed (the higher speed the lower pressure), the pressure above the wing will be LOWER than below. And this pressure difference gives the lifting force that supports the airplane while it is flying. Just physics and nothing more.
     
    Last edited: Oct 30, 2010
  15. MrRudak

    MrRudak

    Joined:
    Oct 17, 2010
    Posts:
    159
    Coool!
     
  16. BlazerRad

    BlazerRad

    Joined:
    Nov 22, 2010
    Posts:
    27
    wow thanks for this helicopter tutorial
     
  17. thelim3y

    thelim3y

    Joined:
    Nov 21, 2010
    Posts:
    4
    After looking at the pdf I just came to post the same thing :) Good catch. For anyone actually interested in flight dynamics it also explains why and how planes have such large wings and how that lifting force is distributed so each square inch of wing is only lifting a relatively small amount of weight. This is also the main lifting force of a wing NOT the pushing down of air as it hits underneath the wing.
     
  18. Muzzn

    Muzzn

    Joined:
    Jan 23, 2011
    Posts:
    406
    Is there a way to stop is shaking so much when you quickly gain or lose height?
     
  19. justicar

    justicar

    Joined:
    Dec 21, 2010
    Posts:
    78
    If you're asking about code, sorry, can't help. If you're asking about "which button should do what" then yes, but it depends on whether you're aiming for a simulation or game.

    I've mapped out a couple different ways to do it as a game (one using accelerometers, the other using just virtual buttons) and that's the way I personally would prefer to play. Basically, the game assumes that there's a competent pilot at the controls. If you're not modeling engine and rotor RPM then there's no need for a throttle, so there goes one control. Regardless of whether you're modeling wind or not, keeping the helicopter in trim (nose pointed in direction of travel) should be assumed. This means that pedal controls are only for circle-strafing. After that it's a vertical slider for collective (altitude) and and either a D-pad or tilt-control for cyclic (direction of flight).

    I think it would be more difficult to do it as a simulation. What's the distinction? For me, a simulator is trying to duplicate the effects seen in The Real World (TM). Well, in TRW, there are four flight controls. If you change one then you have to change the rest. As a professional helicopter pilot in TRW I enjoy doing this. I think an iPhone-style device is way too limiting of a form-factor to do it comfortably and while I can figure out how the controls should work, I know I wouldn't enjoy it. Some movement combinations are trivially simple in TRW and would be obnoxious on an iPhone. IMO.
     
  20. mpgn

    mpgn

    Joined:
    Nov 30, 2009
    Posts:
    70
    I have tried to apply this into my level, it works, but I think my model is off. Instead of going up it goes backwards. Has anyone else experienced this?
     
  21. HolBol

    HolBol

    Joined:
    Feb 9, 2010
    Posts:
    2,887
    Change your models y and z around.]
    Also, brilliant simulation, controls perfectly, and I don't really understand why people saying it's hard to fly, because it's really not :S.
     
    Last edited: Feb 22, 2011
  22. petero181

    petero181

    Joined:
    Feb 23, 2011
    Posts:
    104
    thanks alot
     
  23. justicar

    justicar

    Joined:
    Dec 21, 2010
    Posts:
    78
    I mean this is the nicest way possible, but your explanations on how a helicopter flies is wrong in almost every aspect. A few things right off for you:

    Airflow over the top of the airfoil is high velocity, not low. Imagine two molecules of air hitting the leading edge at the same time. One flows over the upper surface, the other flows over the lower surface, and that meet back together at the trailing edge *at the same time.* The upper molecule has a greater distance to travel but must do so in the same amount of time. And what is speed? Distance over time. You may wish to read up on venturi effect and Bernoulli's Principle.

    Also, rotor RPM (main or tail) is constant, not variable. At least, that's the goal. The tail rotor is direct drive off the main engine. Increasing pitch on the main blades (increase altitude and/or increase airspeed) creates more drag, slowing the blades and bogging the engine down. The response is to roll the throttle on, speeding up the engine back to where it's supposed to be, and subsequently bringing the main rotors back up. The green arc for rotor rpm varies depending on the helo, but it's generally a pretty narrow band (R22 is 101-104%, Schweitzer 300 is ~90-100% but that's because it has no governor to automatically control engine rpm).

    The tail rotor counters the effects of the main rotor (assuming the engine is still driving the mains) by applying lift and thrust parallel and opposite to the torque created from the mains.

    I can explain further if you need, or at least point you to more resources. And, yes, I'm a CFI.

    (and just for fun, I think you meant 8 degrees of movement, not 6. You mentioned the effects of the R axis, but didn't call it out).
     
  24. Novodantis

    Novodantis

    Joined:
    Nov 12, 2009
    Posts:
    95
    I have to say I've never liked this explanation as it confusingly implies (unintentionally, perhaps) that the molecules actually speed up in order to 'catch up' with their corresponding destiny twin they were previously with, which obviously doesn't happen. I think we can just state that the higher velocity causes lower pressure, leading to lift. The phenomenon is notoriously difficult to simplify, so introducing it in brief is bound to be at least a little inaccurate.

    But yes (as others have said too) it should say velocity is higher above the wing, not below it. And indeed, helis will adjust the Collective (rotor angle) rather than the Throttle to control height/airspeed, but mostly everything else is a matter of detail. I think it's good that the OP tried to explain them, as it's an important step toward coding a decent one =)
     
    Last edited: Mar 7, 2011
  25. justicar

    justicar

    Joined:
    Dec 21, 2010
    Posts:
    78
    How have you decided that the upper flow "obviously" doesn't speed up? Especially when you acknowledge the pressure differential with the lower flow. Why is there a pressure differential? Again, read up on venturi effect and Bernoulli's Principle. Maybe Laminar flow, as well.

    Collective is primary for altitude; cyclic is primary for airspeed. Adjusting "rotor angle" is not a valid term. Are you referring to the blades or the disc? What angle? In relation to what? See, everything else was not a "matter of detail." I left it nebulous as to what caused the pitch change that resulted in change in airspeed and altitude because I was trying to keep the post from getting much longer and turning into a lecture. You specifically said that adjusting collective controls altitude *and* airspeed, which is incorrect. These are conceptual errors. (And here's where it gets fun. Technically you could use cyclic to minimally change altitude and collective to minimally change aispeed, but it's piss-poor technique and a result of other effects. I guarantee you that if you claimed as much when going for your checkride that you would fail the checkride.)

    I agree that it was good of the OP to try to explain the issues because the general lack of understanding by those who have gone before has led to some very, very bad "helicopter" games. But anyone seeking to provide any instruction, regardless of the field, has a responsibility to ensure that the information presented is at least reasonably correct (the basics need to be right, even if it's bereft of details). I have recently been informed by numerous people that a helo's throttle makes it fly faster and that's just plain wrong. I don't mean just reading about it here. As in instrument-rated commercial helicopter pilot and flight instructor I find this to be pretty irritating (and is also why I don't tell coders how to program or tell my doctor how to practice medicine). Please correctly infer what I'm implying and don't make me say it point blank.
     
  26. Novodantis

    Novodantis

    Joined:
    Nov 12, 2009
    Posts:
    95
    I didn't mean to dispute that it goes faster, only that the molecules 'meet up' at the end (aka the equal transit time explanation), hence I said the implication to that theory might be unintentional, as my textbooks all discredit it as inaccurate. Perhaps I read that into your statement, in which case my apologies.

    I don't doubt you know your stuff, mate. I agree with all those points (didn't meant to suggest collective controls airspeed, just that it needs manipulating when changing airspeed; but yes that is, strictly speaking, still just maintaining altitude). Information given as an educational preface should endeavour to be correct, of course. I was just saying that some inaccuracy seems inevitable when attempting to simplify such a subject. I can understand if that's annoying though, I feel the same way about many plane 'simulations'.
     
  27. Tinus

    Tinus

    Joined:
    Apr 6, 2009
    Posts:
    437
    Oh, interesting discussion! Haven't done much studying on helicopter physics, so this will help me get up to speed for when I want to implement my own thing.

    I too dislike the inaccurate feel of many 'simulation' games. However, I've also come to accept that you can never simulate everything, and that there will always be inaccuracies somewhere. You need to consciously choose what you simulate and how you do it, with the design goals in mind. As this tutorial doesn't seem to be intended as an X-Plane creation tutorial, I can forgive any inadvertent factual errors. That, and lord knows there are many of them in my own game. That said, I would like to get my yet-to-be-built helicopter done right. :)

    Anyway, there's just one thing that stuck out as odd to me, same as for Novodantis:

    During my studies, I came across this: equal transit time fallacy. This says that equal transit time (based on Bernoulli's principle) is wrong, or not completely correct anyway. The molecules at the top do move faster, but they don't in fact meet up. I can't be too sure about all this as I have not had formal education in the field of fluid dynamics, but this wiki article seems pretty solid, right?
     
    Last edited: Mar 8, 2011
  28. justicar

    justicar

    Joined:
    Dec 21, 2010
    Posts:
    78
    First, if I come across harsh I apologize. Message boards, you know? The subject just happens to be one of the few that I'm good at and occasionally (for very, very large values of "occasionally") I get excited.

    Yes, the equal transmit time fallacy is a valid point, but like I said, I'm trying to not turn it into a lecture and it was my conceit that led me to believe that no one else here would know of it. Yes, I was wrong to state it as I did in such unbending terms. I just hope you can still see the point that I was trying to make. (and then see the secondary one of why I don't want to start lecturing)

    I'm actually a bit surprised, and impressed (happily) that someone was able to articulate *why* there was a flaw with my description. Again, just remember that I'm trying to keep it simple. You'll see that elsewhere. I think most people know that the tail rotor is for anti-torque, but most don't know how it works, what it does or the negative effect (translating tendency). And *no one* talks about force couples for anti-torque. (Force couples are actually deep enough into the theory that I started a fight with my FAA examiner over the subject when I had my CFI ride. He didn't want to hear it even after I showed him in the books. It worked well in the end.) Same thing for pendular action, which most people, CFIs included, teach as being a positive thing when it fact it is exactly what makes helicopters inherently unstable.

    So here is what I would like to see from a helo sim... What the player sees should be a reasonable approximation of how the actual aircraft would perform. It matters not, to me, if the game engine supports the specific, authentic metrics to achieve that. Whatever variables need to be tweaked to get the desired outcome works for me. It's the end result I care about, not what goes into it. By that same token, I'd like to see the control scheme be "proper" for a helicopter. That is, I don't want to see airplane controls because they don't do the same thing. To me, there would be no difference between using airplane controls in a helicopter game and car controls for an airplane game (or tank controls for a sailing game or motorcycle controls for... you get the picture). If you want a helo game then make a helo game. That's my take on it.
     
  29. Delinquente

    Delinquente

    Joined:
    Apr 20, 2011
    Posts:
    22
    Hey,first of all thx for this tutorial,but i can't get it to work....when i finish with the scripting and colliders and when i start the game i cant fly...i press W ,S etc but i cant fly...whats the prob? i added the main rotor and tail rotor to the script
     
  30. Delinquente

    Delinquente

    Joined:
    Apr 20, 2011
    Posts:
    22
    and i didnt made hud and the weapons,ill try to finish that first
     
  31. warzone

    warzone

    Joined:
    Dec 22, 2011
    Posts:
    1
    Hi, I have been recently checking out all of your unity models and to be honest with you they are fantastic. They are that good i am hoping that you will allow me to use these models in my upcoming unity FPS game WAR ZONE. I am aiming to make the best online FPS game available on the web free of charge to all users. If you need an idea of what i am aiming to achieve please check out this link: http://www.rocketeergames.com/redcrucible_test.html
    Hopefully i will develop it even further. I always ask for permission as no if i used it it will violate copyright laws. So take time to think it over and hopefully you get back to me ASAP. You will be put in the credits and of course be made one of the games admins.
    If you do have any questions please do not hesitate to ask. Please reply either to the forums or my email: rsturgess445@googlemail.com

    Many Thanks

    Ryan Sturgess

    WAR ZONE Game developer
     
  32. JanHelleman

    JanHelleman

    Joined:
    Oct 11, 2009
    Posts:
    116
    The tail rotor effect seems to make the whole helicopter stutter. Anyone else experiencing this?
     
  33. JanHelleman

    JanHelleman

    Joined:
    Oct 11, 2009
    Posts:
    116
    To extend my previous post, the following line of code makes the helicopter jerky:

    Code (csharp):
    1.         if (Vector3.Angle(Vector3.up, transform.up) < 80)
    2.         {
    3.             transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(0, transform.rotation.eulerAngles.y, 0), Time.deltaTime * rotor_Velocity * 2f);
    4.         }
    This happens because it slerps between 0, something, 0 and the current rotation, and thus starts to stutter more and more when the distance between the x and z value become bigger. The problem is that making the slerp T element smaller (thus making the effect smaller) creates a bigger max angle on both elements. I tried using a clamp method:

    Code (csharp):
    1.     public float ClampAngle(float angle, float min, float max){
    2.  
    3.         if (angle<90 || angle>270){       // if angle in the critic region...
    4.             if (angle>180) angle -= 360;  // convert all angles to -180..+180
    5.             if (max>180) max -= 360;
    6.             if (min>180) min -= 360;
    7.         }  
    8.         angle = Mathf.Clamp(angle, min, max);
    9.         if (angle<0) angle += 360;  // if angle negative, convert to 0..360
    10.         return angle;
    11.     }
    this does work well when you clamp it to a max angle and than let the helicopter return to origin if no input is given. This however does not give the natural feeling that the original code gives and probably intended to do.

    Can anyone help me with this?
     
  34. newnixon

    newnixon

    Joined:
    Jan 17, 2012
    Posts:
    7
    JanHelleman just check to see if you found and answer to the jerky behavior of the helicopter?
     
  35. newnixon

    newnixon

    Joined:
    Jan 17, 2012
    Posts:
    7
    Ok just found out if you make the height dampening to 200 it goes away. Do you guys know how to make it fly faster? I get it to go forward but it is slow.
     
  36. paullus

    paullus

    Joined:
    Apr 17, 2013
    Posts:
    3
    could you explain how to configure the extra verticle and horizontal axis controls please? and what keys control those inputs? Thanks!


    Paullus
     
  37. sangitashankar

    sangitashankar

    Joined:
    Apr 16, 2013
    Posts:
    3
    Great tutorial, fine and understandable code for a hard simulation like this…
     
  38. M1n3cr4ftrul35

    M1n3cr4ftrul35

    Joined:
    Mar 11, 2013
    Posts:
    8
    Using the current Unity 4.1 (maybe 4.2 as well), I can safely say that while this works, the camera shakes a LOT and goes up very...
    Stupidly.
     
  39. BSBalazs

    BSBalazs

    Joined:
    Jul 5, 2013
    Posts:
    8
    anybody can reupload the files? becaue the link is dead.
     
  40. szymuxik

    szymuxik

    Joined:
    Jul 22, 2013
    Posts:
    13
    500 internal server error...
    What polish say?Dupa!!!!
     
  41. DaveMariner

    DaveMariner

    Joined:
    Jun 30, 2014
    Posts:
    3

    Attached Files:

    JanCDS likes this.
  42. JanCDS

    JanCDS

    Joined:
    Jun 30, 2014
    Posts:
    15
    It seems that his site in general is gone now, might anyone know of a more supported helicopter script (preferably in Js)
    Unless of course enough competent people still lurk on this thread to help a silly (beginning) programmer like me?

    (Edit:) Has anybody found the project file that comes with the pdf? This would help me out a lot.

    Greetings
    -Jan from CDS
     
    MoonbladeStudios likes this.
  43. DaveMariner

    DaveMariner

    Joined:
    Jun 30, 2014
    Posts:
    3
    Hi Jan,

    I didn't find the project file, but then again I didn't go looking much for it. You might be able to uncover it on wayback machine.

    I'd suggest just working through the pdf and posting whatever problems you encounter here. I'm going down a c# route, but might be able to help you out.

    Otherwise if you're wanting an off-the-shelf solution, there are a number of bundles in the Asset Store - the GTA-esque one for about 10 EUR seemed quite good.

    Best of luck,

    - Dave
     
  44. maxwelldoggums

    maxwelldoggums

    Joined:
    Sep 8, 2008
    Posts:
    157
  45. JanCDS

    JanCDS

    Joined:
    Jun 30, 2014
    Posts:
    15
    Many thanks Maxwell, I'll be loading up the project file as soon as possible.

    -Jan from CDS
     
    Last edited: Aug 16, 2014
  46. nevaran

    nevaran

    Joined:
    May 21, 2010
    Posts:
    247
    Im having some weird frame drops when trying to use the helicopter script. Any ideas why?
     
  47. SnotE101

    SnotE101

    Joined:
    Mar 5, 2014
    Posts:
    4
    Any one get a c# version of this. Need to stay pure ;)
     
  48. veilkrand

    veilkrand

    Joined:
    Jun 16, 2016
    Posts:
    1
    This looks very interesting for my project but the link doesn't exist anymore.