Search Unity

UnityFS - Flight Simulation toolkit

Discussion in 'Assets and Asset Store' started by UnityFS, Feb 23, 2013.

  1. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,508
    @Elecman Both EVP4 and EVP5 work perfectly with aircrafts in Unity 4 and Unity 5, respectively. I mean that I plan to simulate aircrafts entirely myself (aerodynamic surfaces, propellers, etc.)
     
    John-G likes this.
  2. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,372
    I see. Now it gets interesting :)
     
  3. Mr-Logan

    Mr-Logan

    Joined:
    Apr 13, 2006
    Posts:
    455
    Heya guys. I need an AI that can fly enemy aircrafts in my game, however I don't know where to even start.
    Can anyone point me in the right direction, or does anyone perhaps have some simple sample code I could peruse?
    Or perhaps a simple playmaker project or a Behavior Designer project?

    I have tried setting an AI up my self in the past, but the aircraft was always moving very unpredictably and often just outright crashed, never actually managed to line up with its intended target (for shooting), etc. xD
     
  4. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,688
    I've made AI system for flight but it is not for sale:



    First of all it is extremely helpful if you played a lot of combat flight simulations (I have played about 15,000 hours).

    You just must just teach them to do what you've learned - which are all basically pretty simple things. You can only output what a pilot would do and you just need to input what a pilot can see, feel and read from the instruments.

    I did that step by step beginning plain leveling the aircraft at a certain height at any speed/power and added it for the rotations after that. It must be able to survive mid air collisions and automatically return to stable flight conditions at this stage. Then you teach it to fly into a direction, you hard code when it is useful to roll into that direction or to use rudder alone.

    After that you teach it little but necessary things like to use rudder to compensate the roll - This all works very well if you just hard code it. Do it rule after rule and let it always decide like you would from your own experience.

    When it can fly to any target and direction then you start implementing a simple strategic decision system - like when is it good to do an Immelmann, when to roll, when to break a turn (because target isn't efficiently reachable at this course and position) etc. etc. etc.
    After that you let them fly and hunt each other to analyze what's going on this makes it possible to optimize things and make first setups for different kind of aircrafts.

    Then you need to add classic things like target course prediction, aiming etc.

    If you aren't really good in (non arcade) flight combat then you should at least watch guncam videos. Usually people are thinking way too much "Hollywood" when it comes to air combat. You can compare this video about strafing with my AI video above because they are basically doing the same thing - a boat can be considered a static target for cannons.



    Energy conservation is one of the most important things in classic close air combat. Altitude can be always converted to energy and vice versa. So one of the strategies for any good AI will be to save E. Turning destroys energy. There are "Boom and Zoom" (energy) fighters (like the german WWII aircrafts) and "turn fighters" (like the Spitfire or the Japanese A6m) it depends on their flight characteristics. Any AI needs to learn that difference for its decisions too.
     
    Last edited: Jun 23, 2015
    Karearea likes this.
  5. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,688
    Video of another older AI example in an even more uglier environment.

    They work like primitive machines, they are really plain stupid and still need fine tuning. But you can see 3 completely different types of aircraft here. Fighter, light bomber and heavy bomber.

    The job is to take off, reach some altitude, head to the boat and attack it. After that fly away and turn at a safe distance from the boat, then head towards the boat and attack it again.

    This is a real time recording without any edits. You can see that the settings for the AI are clearly not strict enough. As a result it misses sometimes or even comes in at a wrong angle - stupid as it is it realizes it when it is already too late so at the end it has to give up the attack because it can't turn in for the final strafe run under these conditions.
    Strafing generally looks easier than it is. Hitting a 60m long boat while coming in at 500 km/h needs precision and it is not easy to implement such a sensitive but fast behavior. But actually when you compare it to videos from real WW2 pilots it looks often very similar. They all do a lot of spray and pray.

     
  6. Karearea

    Karearea

    Joined:
    Sep 3, 2012
    Posts:
    386
    Very cool- out of interest how do you imagine you'd approach divebombing (I have to ask, you've put a Dauntless in there!)

    The Hurricane in particular looked actually quite close to gun camera footage from the period in terms of accuracy.
     
    Last edited: Jun 24, 2015
  7. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,688
    Drop tests (and also try to calculate it) and creating a "virtual" bombsight based on that. Virtual bombsight in this case means to create a virtual target and switch to it during the last phase of the attack. The virtual target's position depends on the AI aircraft's speed & position and on the position of the real target object (or its predicted position).
    From the aircraft AI's point of view this is the same job as strafing except that the position of the target will change faster and it has to follow a rule when to release the bomb instead of when to trigger the gun which is basically the same.
     
    Karearea likes this.
  8. Mr-Logan

    Mr-Logan

    Joined:
    Apr 13, 2006
    Posts:
    455

    Thank you!
    I actually tried doing something like this approach last time round. It just ended up feeling so bloated that in the end I couldn't find my way around the code anymore and any edits I made just made the AI seem dumber and dumber.
    But I'll try to do it again following your instructions. =)
    I'll be posting results here when I have some.
     
  9. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,688
    I guess sometimes bloated code is by far the fastest solution. You shouldn't use a clean hyper multifunctional über-tool and wear a business dress when the right way to do something just requires a hammer and some time and when the right dress would be a dirty overall.
    My overall style looks like a kind of total mess for anyone else anyway, that's how I've did it when I started to code more than 30 years ago and I will never change that style. My approach for the AI is clearly something that someone who writes "beautiful" maintainable code would never do but I feel lost in most of the code those people.
    Bloated code needs to be prepared for later reuse too :)
     
  10. Mr-Logan

    Mr-Logan

    Joined:
    Apr 13, 2006
    Posts:
    455
    Well when I can't keep track of my own code is when I figure I'm probably doing something wrong, heh.
    That said, this time around I plan on using Behaviour Designer (well that or PlayMaker, I haven't quite decided yet) so it's far easier to maintain the overview/scope of the beast, while still being able to do what ever I want.
    I plan to flesh it out tomorrow, today has been used making an initial terrain, though it seems to be way too small, and then polishing my aircraft as it the controls felt slightly wonky, they are much better now, which should, I assume also make it much easier for an AI to fly the aircraft.

    Btw. has anyone heard anything new in the case of the update we were told about 3-4 months ago? (The one with flaps, a fix for wheel colliders, etc.)
     
  11. Karearea

    Karearea

    Joined:
    Sep 3, 2012
    Posts:
    386
    I think the fix was going to be released when the wheel collider issues were worked out- they seem to behave this way in 5.* by design though. It looks like you need to dynamically check the mass of the rigidbody and update the suspension settings on the fly, which is what Edy's pack does- I haven't yet got that working nicely once in flight though, it seems to affect the rigidbody physics in the air.

    It's all incredibly frustrating as the rest of the flight behaviour is still great- I'm just having to start in the air and ignore the landing side of things for now.
     
  12. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,372
    It is probably best to use Edy's pack instead. The current collider issue will likely never be fixed judging from the lack of Unities interest on this particular subject.
     
  13. Karearea

    Karearea

    Joined:
    Sep 3, 2012
    Posts:
    386
    Confirming Edy's pack works! I was instantiating and setting the component active in the incorrect order. Works really nicely too- more subtlety to the whole thing. Having brakes set and throttling up causes the whole aircraft to lean forward. So yup, definitely a solution to the wheel collider problem!
     
  14. Mr-Logan

    Mr-Logan

    Joined:
    Apr 13, 2006
    Posts:
    455
    I actually managed to get it working back when i noticed it (I just have a script that sets wheel torque to a very small value). But still.. this was 3-4 months ago, flaps have been hinted at for a lot longer, my game admittedly doesn't need them, but the lack of development just kinda frustrates me.
     
  15. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,372
    I don't thinks so. In my understanding it can't be fixed. Just use Edy's package.
     
  16. Mr-Logan

    Mr-Logan

    Joined:
    Apr 13, 2006
    Posts:
    455
    upload_2015-6-26_1-16-42.png

    So far my AI can take off and fly level.
    However it is very wobbly, since at the moment I'm just making hard changes.
    Many values can be set to a range -1 to 1 and I do just that, -1, 0 or 1. I should be able to fix some of that, but not too much as it does kind of give them character to wobble a little such olden timey aircrafts.
    I'll probably be playing around with some banking manouvers next. Working my way up to following a target.
     
  17. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,688
    I guess this is playmaker?
    Why do you think old aircrafts would wobble? They do it in funny comics but not in real life.
     
  18. Mr-Logan

    Mr-Logan

    Joined:
    Apr 13, 2006
    Posts:
    455
    Nah this is behaviour designer. (a visual behaviour tree maker)
    And on the note of wobbling, the game isn't meant to be a hyper realistic flight simulator, I rather want to capture sort of the feel of flying games from the 90'ies where they were arcade'ish because making them hyper realistic would just not be possible, but they still tried to be sort of as serious as they could.
    I don't even know how many hours I sunk into Dynamics Red Baron, or games like Aces of the Pacific, Aces over Europe, A10 Tank killer (which was probably the most realistic of those 4), and many more. I feel like flying games have just become too complex for most people, so I'm trying to go for something charmingly arcade'ish though while not being tooney and silly.
    Also I'm aiming at sort of pre world war one steampunk theme, so the aircrafts I want in the game would be slightly wonky and wobbly. So having them not fly completely straight is just a bonus in my book. =)
     
  19. Mr-Logan

    Mr-Logan

    Joined:
    Apr 13, 2006
    Posts:
    455
    When I say pre ww1 steampunk theme, I don't mean set in our world, but set in an alternate world where the technological level is somewhere close to, but has not yet reached the ww1 state of technological development.
     
  20. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,688
    A friend of mine started to make such a steam punk arcadish flight sim game with Unity in 2007. He use a giant catapult for takeoff which was funny.

    I never used any visual tool for code. What is the benefit of it?
     
  21. Karearea

    Karearea

    Joined:
    Sep 3, 2012
    Posts:
    386
    Was that related to A-10 Cuba? I spent a seriously crazy amount of time in that, so much attention to detail, even back then. I remember strafing tanks and actually seeing the projectiles they fired streaking through the air.

    How are you handling the behaviour designer instructions being conveyed to actual control inputs? i.e. high level AI behaviours to low level input adjustments?
     
  22. Mr-Logan

    Mr-Logan

    Joined:
    Apr 13, 2006
    Posts:
    455
    @VIC20 It's not something I've done much of, but it sort of gives me a better more organized view of what I'm doing.

    @ddnharris Looking at the screenshots I'd say the games look very much the same. However I googled a bit further, and what I discovered is this. In 1995 Parsoft released A-10 Attack! which was well received, in 1996 Parsoft then released A-10 Cuba. However, Dynamix released A-10 Tank Killer way back in 1989 on DOS and in '90 on Windows, so they are 5 years between them and they are from 2 different developers and publishers, so I don't think they have had much to do with each other.
    Actually in 1996 Dynamix released a sequal called "Silent Thunder: A-10 Tank Killer II" of which I have however only ever played the Demo (I was a master at landing on tiny airstrips in the jungle however xD)

    Rather than mapping directly from the behaviour designer to the aircraft I'm doing it through "Actions", which are custom scripts that can be used as objects inside
    Behavior Designer. So rather than do everything through BD I'm utilizing it to give me a graphical view of the big picture, while still working on the smaller details through code.
    I'm using a script called "AiPilot" as sort of a middle between the BD Action and the actual aircraft, so the AiPilot script has references to all the parts of the aircraft.
    I've been stuck on the follow target script however. But earlier today I discovered that there's an aircraft (albeit a very simplistic one) in the standard assets thingy, so I'm trying to see if I can somehow utilize that code with my aircraft as the navigation stuff works very well in the demo scene. However it seems to work less well on my aircraft :D
     
  23. ibyte

    ibyte

    Joined:
    Aug 14, 2009
    Posts:
    1,047
    So has Chris abandoned this project?
     
  24. UnityFS

    UnityFS

    Joined:
    Feb 10, 2013
    Posts:
    127
    No, apologies, the fix hasn't been quite as straightforward as I had anticipated. Particularly whilst trying to keep Unity 3xx , 4xx compatibility in mind and to make peoples existing aircraft upgrade gracefully to Unity 5. I apologize for the inconvenience I realize the fix is a long time coming.
     
    Mr-Logan and julianr like this.
  25. ibyte

    ibyte

    Joined:
    Aug 14, 2009
    Posts:
    1,047
    Hi Chris, thanks for coming by to give everyone an update.
     
  26. julianr

    julianr

    Joined:
    Jun 5, 2014
    Posts:
    1,212
    Hi Chris, does this mean you've fixed it for Unity 5 and you'll have an update out soon? :)
     
  27. UnityFS

    UnityFS

    Joined:
    Feb 10, 2013
    Posts:
    127
    Hi all,

    UFS is now fully compatible with Unity 5. I have just submitted the initial fix to the asset store. Shortly following will be another update with flaps,airbrakes and better handling characteristics for the demo aircraft.

    Those of you that can not wait for the asset store update, please find fixed files here:
    https://www.dropbox.com/s/np45epukqh3sk7y/UFSUnity5Fixes.zip?dl=0

    Simply overwrite your Aircraft and LandingGear.cs scripts in the UFS folder and you should be good to go.

    Enjoy!

    Cheers,
    Chris
     
    Mr-Logan, John-G, VIC20 and 4 others like this.
  28. julianr

    julianr

    Joined:
    Jun 5, 2014
    Posts:
    1,212
    Awesome! Will pick this up now!!
     
  29. UnityFS

    UnityFS

    Joined:
    Feb 10, 2013
    Posts:
    127
    Julianr enjoy :) you will need to use the above script to overwrite your aircraft and landing gear scripts.
     
  30. julianr

    julianr

    Joined:
    Jun 5, 2014
    Posts:
    1,212
    Thanks. I've been waiting for this! 121 (2000x2000) terrains need a plane :)
     
    Mr-Logan and UnityFS like this.
  31. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,372
    This is great news. Keep up the good work!
     
  32. julianr

    julianr

    Joined:
    Jun 5, 2014
    Posts:
    1,212
    Anyone integrated this with UFPS, or a 3rd person controller? I'm thinking along the lines of using Rewired for the control switching between flight and person. Looks like I'm going to have to do some manual work on integrating uFS as it does overwrite UFPS settings.
     
  33. ibyte

    ibyte

    Joined:
    Aug 14, 2009
    Posts:
    1,047
    julianr likes this.
  34. Karearea

    Karearea

    Joined:
    Sep 3, 2012
    Posts:
    386
    I've been using both with Rewired, had to edit the UFS input scripts to do so though. I just turn off all the UFS objects when UFPS is active, and vice versa.

    You just need to go through the input scripts and add a rewired case where there's a Unity input case, ie:

    in InputEditor.cs

    After:

    case InputController.InputSource.InputManager:
    {
    ShowAxisInputManagerSettings( name, target );
    }
    break;

    Add:

    case InputController.InputSource.Rewired:
    {
    ShowAxisRewiredSettings( name, target );
    }
    break;

    And After:

    private void ShowAxisInputManagerSettings( string name, InputController target )
    {
    target.AxisName = EditorGUILayout.TextField( name + " Axis Name", target.AxisName );
    }

    Add:

    private void ShowAxisRewiredSettings( string name, InputController target )
    {
    target.AxisName = EditorGUILayout.TextField( name + " Axis Name", target.AxisName );
    }

    And After:

    case InputController.InputSource.InputManager:
    {
    ShowButtonInputManagerSettings( name, target );
    }
    break;

    Add:

    case InputController.InputSource.Rewired:
    {
    ShowButtonRewiredSettings( name, target );
    }
    break;

    And After:

    private void ShowButtonInputManagerSettings( string name, InputController target )
    {
    target.ButtonName = EditorGUILayout.TextField( name + " Button Name", target.ButtonName );
    }

    Add:

    private void ShowButtonRewiredSettings( string name, InputController target )
    {
    target.ButtonName = EditorGUILayout.TextField( name + " Button Name", target.ButtonName );
    }


    Also, In InputController.cs

    Add Rewired as an input source like so:

    public class InputController
    {
    public enum InputSource
    {
    InputManager = 0,
    Rewired,
    Reflected,
    Manual

    And after:

    case InputSource.InputManager:
    {
    if ( "" != AxisName )
    {
    inputValue = Input.GetAxis( AxisName );
    }
    else
    {
    Debug.LogWarning( "InputController - Trying to get input from InputManager with no axis defined." );
    }
    }
    break;

    Add:

    case InputSource.Rewired:
    {
    if ( "" != AxisName )
    {
    inputValue = Rewired.ReInput.players.GetPlayer(0).GetAxis( AxisName );
    }
    // else
    // {
    // Debug.LogWarning( "InputController - Trying to get input from InputManager with no axis defined." );
    // }
    }
    break;

    Hope it's ok by you Chris to put this up!
     
  35. julianr

    julianr

    Joined:
    Jun 5, 2014
    Posts:
    1,212
    Last edited: Aug 25, 2015
  36. ibyte

    ibyte

    Joined:
    Aug 14, 2009
    Posts:
    1,047
    @ddnharris So uFS support for reflection was not useable with Rewired and required script modification instead? Just wondering.
     
  37. Karearea

    Karearea

    Joined:
    Sep 3, 2012
    Posts:
    386
    That's what I found- I guess you could probably write a script to get specific rewired values and show them publically, and reflect that? I found it easier to change the input scripts, with the added advantage you can then change the input source on a control surface and keep the same axis names (assuming you're consistent with rewired actions compared to old actions)
     
  38. ibyte

    ibyte

    Joined:
    Aug 14, 2009
    Posts:
    1,047
    @ddnharris Have not really looked at Rewired too closely yet so I was not sure if there was already a Rewired script that you could have reflected the values from. Thanks for the info!
     
  39. julianr

    julianr

    Joined:
    Jun 5, 2014
    Posts:
    1,212
    Hi, I've applied the fix for Unity 5 and tested the example scene. The plane moves forward on its own, when it should be static, any ideas?

    edit: no engines on

    edit: think it may be down to the positioning of the wheel colliders! From memory I had the same issue with car vehicles.
     
    Last edited: Aug 30, 2015
  40. julianr

    julianr

    Joined:
    Jun 5, 2014
    Posts:
    1,212
    @ddnharris - hi, any tips on the settings required to get the ignition working with Rewired? Everything else seems ok. I've created a keyboard map for it and an action, but no joy.
     
  41. Karearea

    Karearea

    Joined:
    Sep 3, 2012
    Posts:
    386
    @julianr - I start my plane when entering/exiting by setting the engine properties directly, so I never looked at getting the ignition working with Rewired. There're possibly a few additions you need to make in the input scripts to control the ignition settings- Maybe it handles the input a bit differently due to the ignition requiring a key to be held down before moving to the next state? Good luck!
     
  42. julianr

    julianr

    Joined:
    Jun 5, 2014
    Posts:
    1,212
    good suggestion on starting the plane. I was obviously over complicating it at 2am :) and I've tried a few things, including holding the button down, so I decided to use button mouse down for throttle as I have not yet figured out how to keep the throttle fixed at that rate when pressing a button, it always seems to reset the button value down to 0. Thanks!
     
  43. Karearea

    Karearea

    Joined:
    Sep 3, 2012
    Posts:
    386
    Sounds like gravity settings for the action. Setting gravity to 0 means the input only returns to 0 if you apply the negative button.

    Edit: Create an axis for the throttle with positive / negative buttons rather than controlling it with a single button.
     
    julianr likes this.
  44. julianr

    julianr

    Joined:
    Jun 5, 2014
    Posts:
    1,212
    thanks I'll give that a go. I presume the same would apply for the break.
     
  45. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    Thanks for this workaround

    The asset store is certainly very slow sometimes. I just checked and it still has not arrived in the asset store.
     
  46. pixelquaternion

    pixelquaternion

    Joined:
    Jun 28, 2014
    Posts:
    122
    Hi there,

    Is this asset still getting develop?

    We are making a ww2 flight simulator and we want to know if this asset would answered our need like realistic flight physic, 3d cockpit instruments support?

    I also read in the reviews that there is no flaps support if so how can we make a ww2 plane simulation without it?

    Thank for an y answers.
     
  47. yotam180

    yotam180

    Joined:
    Aug 29, 2014
    Posts:
    1
    Hi.
    From my experience with this asset it would be more than enough for your needs. It supports 3d cockpit instruments, it has a realistic flight physics.

    About flaps support, flaps can be easily added. I did it once (I don't remember how) but you should just look at the script that calculates the total forces on the main rigidbody, and multiply lift & drag by (approximately) 1.05-1.2 (based on the flaps position).
     
    Karearea likes this.
  48. steveh2112

    steveh2112

    Joined:
    Aug 30, 2015
    Posts:
    314
    this looks amazing. one question through, i didn't see any parameter to configure aircraft weight. isn't that kinda important?
     
  49. Karearea

    Karearea

    Joined:
    Sep 3, 2012
    Posts:
    386
    Rigidbody mass set in realistic kg works fine @steveh2112 -you can also update it at runtime to simulate fuel consumption, with a noticable change to aircraft handling, although you'll need to set this yourself.
     
    John-G likes this.
  50. pixelquaternion

    pixelquaternion

    Joined:
    Jun 28, 2014
    Posts:
    122
    Hi Yotam,

    Thank for the info i will have more questions later but for the moment i have to finish a model.

    Regards
     
    Tomahawkppc likes this.