Creating a Flight Simulator in Unity3D (Part 1)

Sdílet
Vložit
  • čas přidán 15. 06. 2024
  • This video shows how to make a simple flight simulator, from basic theory to implementation
    Original blog post: vazgriz.com/346/flight-simula...
    Github: github.com/vazgriz/FlightSim
    itch.io: vazgriz.itch.io/flight-sim-pa...
    0:00 Intro
    1:19 Physics of Flight
    7:22 Implementation
    19:15 Conclusion
    #gamedev #unity3d #flightsimulator
  • Věda a technologie

Komentáře • 140

  • @chiefcloudyeye0489
    @chiefcloudyeye0489 Před rokem +60

    I'm amazed and saddened by the lack of views and comments on this video. Love them all, very well thought out and clearly researched and understood before implementation. Keep up the good work!

    • @Alimentasable
      @Alimentasable Před rokem +3

      Guy has 3k subs, the video was barely an hour old when you commented. Stop being so dramatic

    • @MaksMikhnevych
      @MaksMikhnevych Před rokem

      Then share this video on your social media.

    • @quincyames2014
      @quincyames2014 Před 7 měsíci

      bad intro lol

    • @sladethegreat1194
      @sladethegreat1194 Před 2 měsíci

      Hey. Here we are a year later, and I’m an indie dev, learning about the physics of planes to make a simple iPhone game.

  • @TrentonV
    @TrentonV Před rokem +38

    Man, this is super cool! I never thought about the unrealistic physics in other video games, and I respect the time and effort you've taken to create this passion project
    Definitely looking forward to your next upload!

  • @NDSno1
    @NDSno1 Před 9 měsíci +2

    I;m amazed by the amount of effort you put in the presentation to explain the physics in detail, which non other video on CZcams about flight physics for game dev has done. Great job. You deserve a lot more sub and view

  • @supm8te751
    @supm8te751 Před 10 měsíci +4

    your passion burns throughout the whole video. Im making a mech game that involves air combat(might extend to space battles) and fighter jet target systems and your in depth explaination really helps me understand more about the essence these games strive to recreate, thank you and subscribed.

  • @TheNerd484
    @TheNerd484 Před rokem +22

    17:06 The reason you use the cross product is because the g vector is perpendicular to both the velocity vector of the aircraft and the rotation vector of the turn that craft is making. Due to the fact that the rotation vector is always perpendicular to the velocity vector in most maneuvers, the magnitude of the g load is equal to the product of the magnitudes of the velocity and rotation vectors, hence why the math works out like that.
    I hope that makes sense

  • @dreamisover9813
    @dreamisover9813 Před rokem

    Found this from reddit. Your tutorial blog posts are awesome!

  • @RyanLee-up9ej
    @RyanLee-up9ej Před rokem +5

    This is so easy to follow. You did a great job keeping the material clear and concise. Great work!

  • @picklechin2716
    @picklechin2716 Před 6 měsíci +42

    You call me nerdy for playing dcs, yet here you are coding.

  • @yah3136
    @yah3136 Před rokem +3

    Thank you so much for such detailed but clear presentation.

  • @EeveeMae
    @EeveeMae Před rokem

    Thank you man, I have been trying to make a flying simulator for so long, this tutorial is so helpful.

  • @jagc3763
    @jagc3763 Před rokem +1

    I'm amazed! Thank you for this piece of art!

  • @OmPuter
    @OmPuter Před rokem +1

    you are my professor.... idk why you did this and made it open source, bravo! many many respect!

  • @itzjustrandom5673
    @itzjustrandom5673 Před 10 měsíci +3

    even if dont use unity, your explanation skills amaze me, it is super interesting and it made me think about learning unity. Cool video

  • @claxvii177th6
    @claxvii177th6 Před rokem +1

    THE PHYSICS SUBSTEP IS GENIUS!!! SOLVED MY PROBLEM ON A INDIVIDUAL SURFACE SIMUATION!

  • @sdsdfdu4437
    @sdsdfdu4437 Před rokem +5

    This is incredible. Thank you so much for releasing the source code

  • @RogueBeatsARG
    @RogueBeatsARG Před 29 dny +1

    THIS IS WHAT I NEED, a More Realistic Physics, Ace Combat, people think doing Cobras on AC is fun but doing a Cobra in a more realistic game is satisfiying as fuck

  • @michaelalaku1536
    @michaelalaku1536 Před rokem

    thanks for the tutorial, it was really helpful. I am new to Unity3D and C# and I wish to learn more from you.

  • @cgpilk
    @cgpilk Před rokem +4

    Awesome! So well explained, thanks!

  • @narvi2
    @narvi2 Před rokem +1

    Great video! Looking forward for the next part.

  • @sayochikun3288
    @sayochikun3288 Před rokem +1

    Visuals are very helpful and quick. Nice

  • @M4ssExtinction
    @M4ssExtinction Před 10 měsíci

    As a game developer I'm impressed on how you did this!

  • @vast634
    @vast634 Před rokem +1

    Very nice overview on the calculated forces and flight mechanics in general. Maybe you can add keyboard+mouse control to your demo too.

  • @imDanoush
    @imDanoush Před rokem

    Very interesting introductory video with awesome animations! gg.

  • @atencaogamer
    @atencaogamer Před 11 měsíci

    One thing Ive been looking in flight sims is the feature to create dynamic campaigns. Sure having a good model is the main thing but what you need it for is also important

  • @larrysouthern5098
    @larrysouthern5098 Před rokem

    I've wanted to do this for a long time.
    THANKS
    🐦

  • @lukarausch7907
    @lukarausch7907 Před rokem +1

    Loved the video. You have big potential boy

  • @RUDERUDYTUTORIALS
    @RUDERUDYTUTORIALS Před rokem

    This is really awesome tutorial video great work man.

  • @TheDreamFx
    @TheDreamFx Před rokem

    Great Video! I think you could maybe have shortend the implimentation and formular derivation part. Since it think most of it is straight forward. Thanks for the nice project. I'm interested where it's headed :)

  • @GonziHere
    @GonziHere Před rokem +1

    Firstly, absolutely great tutorial. Love it.
    I've calculated drag in the full formula way. It's easy, because you have several of those numbers as constants, so you can precalculate them (I did it on the paper, basically) and you'll have realistic calculation in the end. (the part of it is the drag area which has findable values of say 0.3 times the area, which you can calculate per axis).
    You can use real engine force, real drag coefficients, real lift values of a given plane and it will fly comparably... (as in, it's not a sim, but it kinda acts like one). My jet could achieve the real max speeds, climbs etc. with an error of a few percents without me tweaking anything.
    You are going the hand tweak route, which will need much more tweaking as compared to tweaking the "real" values a bit (from my experience).

    • @GonziHere
      @GonziHere Před rokem +1

      Seeing your rotations - I was simulating it more realistically and then I've implemented Fly By Wire on top of it (player rolls, plane also pitches, so FBW compensates the pitch).
      You could try that, it was a fun thing to try to implement and I've personally enjoyed the end result, where the plane can be twitchy and self correcting. It was what made it feel "physical".

    • @akshatmaurya3964
      @akshatmaurya3964 Před 11 měsíci

      @@GonziHere how did you go about implementing Fly By Wire in unity? seems interesting to try

  • @larryneagu1180
    @larryneagu1180 Před rokem +5

    This is one of the best approachings to putting together flight in unity. It's still slightly too realistic - at first - but it's an awesome way to build gameplay around flying skills. I've been playing with this for a few days now - I ran into a weird bug I cannot trace the source off. After a couple of seconds or more, I lose all lift in all surfaces - with gizmos visible I can see them just getting smaller fast and disappearing. I use the stock airfoils with reduced lift and drag for (75 and 35 respectively).
    This can be a very successful asset store template with minimal additions: 1) multiple targets, 2) rotor planes (biplane and mono) 3) slightly more arcade controls 4) sound support. I would be more than happy to provide whatever art you need to help you put this up on the asset store (or just upgrade the git project).
    edit - resetting the collision box on the plane to its original scale/values solved the problem.

  • @ABaumstumpf
    @ABaumstumpf Před 11 měsíci

    AceCombat and Project Wingman both have more involved physics than what you have shown here. They just have the weapons and AI configured to make it easy, but energy, stall, induced drag - they have all of that. I loved to play around the time of AC3-ACX and you could absolutely ignore tactics but if you do consider your mission target, the aircraft you have, its configuration and loadout and fly according it makes a big difference.
    Some aircrafts there had abysmal low speed acceleration and high induced drag for yaw. So if you keep some height, don't turn too hard and stay at cruise speed the aircraft feels a lot more nible and getting a solid lockon becomes way easier.

  • @albertomodrono4320
    @albertomodrono4320 Před 6 měsíci

    Great video. The result is stunning!! I have one little question. The definition angle of attack wouldnt be the angular difference between the velocity and the nose of the plane, instead of the angle between y and z components of velocity right away??

  • @nexuzinnovation-com
    @nexuzinnovation-com Před 10 měsíci

    Thank you for sharing this useful information.

  • @galsmith2098
    @galsmith2098 Před 6 měsíci +1

    Just found this series. Looks amazing!
    Can I program it to work with a keyboard and a mouse (like war thunder for example)?
    I don't have a lot of coding experience(only scratch), how hard will programing it like this be?
    Is there any chance you will make a short video about it?😬
    Thanks!

  • @justhanging2569
    @justhanging2569 Před 9 měsíci

    Great video, commenting for the algorithm!

  • @fishercawkey
    @fishercawkey Před 11 měsíci

    Superb work on this!

  • @MSPhysicsForFun
    @MSPhysicsForFun Před 11 měsíci

    super great I will try in MSPhysics too.

  • @brodakarat6340
    @brodakarat6340 Před rokem +1

    I kinda wanna make all the forces apply at the appropriate positions instead of always at center of mass, the program a flight stability assist computer and this can be damaged by bullets or electrical failure

  • @ARandomHumanBein
    @ARandomHumanBein Před 9 měsíci +1

    You should try out IL-2, it's a WW2 flight simulator that is basically in between War Thunder and DCS in terms of Complexity and Realism

  • @bennguyen1313
    @bennguyen1313 Před rokem

    Would love to hear your thoughts on a 2D-game that re-creates a cockpit screen. For example, in the game DCS:AH-64D there is a weapons MPD (multi-purpose-display) where you can select missiles and code them for the target.
    The game would take user-input, update the screen, and issue a sound. Would Unity be the preferred tool?

  • @xXmobiusXx1
    @xXmobiusXx1 Před 9 měsíci

    Ah you don't know about the beloved flight sim series back in the days of DOS and win 98, the Jane's combat simulations series like USAF or Fighters anthology.

  • @MrZtapp
    @MrZtapp Před 4 měsíci

    Great tut, thanks.

  • @bedirhansakaoglu8767
    @bedirhansakaoglu8767 Před rokem

    Hey man quick question, why did you multiply the local velocity on the y axis by negative one while calculating the angle of attack? Great work by the way!

    • @Vazgriz
      @Vazgriz  Před rokem +1

      I wanted AngleOfAttack to be positive when the nose direction is "above" the velocity direction. If I just used the velocity.y component directly, the AOA would be opposite of what I wanted. This problem could also be solved by pulling the negative outside of the function ( -Mathf.Atan2(...) ).
      Basically, the math behind Atan2 would make the value negative, so I need to multiply by -1 somewhere

  • @BlackM3sh
    @BlackM3sh Před rokem +2

    19:06 Absolute perfection!

    • @GonziHere
      @GonziHere Před rokem +1

      Yeah, I've totally lost it there :D :D :D

  • @r4c732
    @r4c732 Před rokem +1

    Sheeesh, nice video man! Learned a lot from this, btw I have a question.. At low speeds the aircraft tends to preserve momentum from it's previous direction when turning, how do I prevent this from happening? I just can't seem to figure it out

    • @Vazgriz
      @Vazgriz  Před rokem

      That's intended behavior. At low speeds, the plane creates less lift, so when you turn, the velocity will take more time to align with the new direction you're facing

  • @randomdude5634
    @randomdude5634 Před 2 měsíci

    great vid man :D :)

  • @R1kyzzzz
    @R1kyzzzz Před rokem

    Killer. Keep going bro

  • @jaybabcock9123
    @jaybabcock9123 Před rokem

    best line of the whole video: "Dont ask me why, because I discovered it by accident"

  • @zantherhayes7229
    @zantherhayes7229 Před 8 měsíci

    Over G fighters was a solid midline between sim and arcade

  • @markaron9356
    @markaron9356 Před rokem

    I like how the plane just turns into smoke

  • @CYON4D
    @CYON4D Před 8 měsíci

    Great work.

  • @ChucksSEADnDEAD
    @ChucksSEADnDEAD Před rokem

    You could get Rho based on player altitude by using the perfect gas law.

    • @badbeardbill9956
      @badbeardbill9956 Před rokem

      Nah, you need both temperature and pressure for that. Can just use a lookup table or a basic scale height equation though

  • @naronga6857
    @naronga6857 Před rokem

    Could this be expanded to a space sim kinda game? Having a seamless transition from space to atmosfere fligh, like kerbal or a more realistic star citizen? Or would this solution feel too arcady for a more simulation like game?

  • @smollime117
    @smollime117 Před rokem

    vert underrated

  • @pygarg26
    @pygarg26 Před 6 dny

    Amazing

  • @taktischesgenie331
    @taktischesgenie331 Před rokem +1

    Hey if you like tiny combat arena you should check out Strike Fighters 2

  • @torusx8564
    @torusx8564 Před rokem

    Thank you

  • @michalkmet8351
    @michalkmet8351 Před 9 měsíci

    1st sentence got me dieing - I like to play flight sims as Ace combat and project wingman 💀💀💀

  • @darkveneno6155
    @darkveneno6155 Před rokem +1

    You can make it so that the pilot can endure higher G-Force for a short amount of time.

  • @joshuasteward6672
    @joshuasteward6672 Před 3 měsíci

    When turning, shouldn't the nose of the craft experience a force pushing it back towards the direction of movement? Currently it seems as if when I nose up and then let off the controls, the nose "sticks" where I left it, whereas it seems as if other flight games model how air resistance exerts a force on the plane so that it turns back in the direction it is headed.
    I'm probably not explaining it super well, but I was wondering how to implement this in my own project.

    • @Vazgriz
      @Vazgriz  Před 3 měsíci

      You're right, there should be a force like that. That's the stability force that real planes experience. A simple way to model it is by applying a torque that multiplies with AOA.
      I did not include it in my simulation for simplicity. The way the plane behaves is like a plane with neutral stability (holds nose attitude). A more realistic behavior would be to have positive stability (nose pulled towards velocity vector).

  • @daxylikecatz7050
    @daxylikecatz7050 Před rokem

    Bro... The flap are inverted normally if you want to create a up lift you make the flap point down

  • @bubchudlar5629
    @bubchudlar5629 Před 6 měsíci

    I'm trying to follow along, but I can't figure out how to implement inputs for the throttle, which makes it impossible to test if the thrust and inertia stuff is working. What part of the github repository should I be looking in?

  • @PC_YouTube_Channel
    @PC_YouTube_Channel Před rokem

    I'm surprised you hand-tuned the coefficient of drag curve with AoA. It seems like it would be easier and more realistic to estimate the cross-sectional area of the plane with AoA (say, linearly interpolate between the nose-om area and the belly-on area) then you would just have to tune a single scalar and the dependence of AoA should be very realistic without any more calculations than you're already doing.

    • @Vazgriz
      @Vazgriz  Před rokem +1

      The coefficient of drag uses an animation curve based on air speed. The Scale6 function does sort of blend between nose-on drag and belly-on drag. However it specifies the drag coefficient directly instead of calculating based on area. The game designer could do those calculations offline and simply plug in the numbers.

  • @MinhLuong1006
    @MinhLuong1006 Před 26 dny

    Can you do tutorial videos about the tank you uploaded on CZcams?

  • @mrpotato8196
    @mrpotato8196 Před 3 měsíci

    The Scale6 function is a really nice idea, I can see myself using it for other things too :)
    *For those whose plane refuses to leave the ground:* My plane refused to get off the ground since aoa = 0 hence CL = 0 and lift = 0, so I had to add an angle of incidence (set by user in degrees, converted to radians) to the angle of attack, this will also make the simulation more realistic since most planes have their wings rotated slightly backwards
    This is a really nice video explaining angle of incidence:
    czcams.com/video/AUmL8mIUxyc/video.html

  • @Firebend11
    @Firebend11 Před 2 měsíci

    8:32 how do you add specific keybinds for the throttle?

  • @foreignwarren7361
    @foreignwarren7361 Před rokem

    Please keep going, subbed and loving it!!! Please show us throttle, gears, etc etc

  • @Trillion_Empire
    @Trillion_Empire Před 11 měsíci

    Ive tried making my own jet and i copy the code and do what it said and theres a bunch of error messages, i think it needs a bunch of floats added to make it work but i still dont know what to add where. please could you make a follow up video walking us through every process

  • @Firebend11
    @Firebend11 Před 2 měsíci

    0:42 dcs also has insane storage space for my tiny ass laptop

  • @blaisepascal3804
    @blaisepascal3804 Před 8 měsíci

    if you think of the grind as fun playime, not agonizing grinding, war thunder is quite fun

  • @grangerhighschoolvirtualre7070

    Awesome! Can you use the pc keyboard to play this in Unity?

    • @Vazgriz
      @Vazgriz  Před rokem

      No. Only gamepad control is implemented. You can of course download the project and implement it yourself.

    • @larryneagu1180
      @larryneagu1180 Před rokem

      I bought a controller just for this. The experience is so much better.

    • @tyen2231
      @tyen2231 Před rokem

      @@Vazgriz can you help me implement keyboard input

  • @sapphiregaming4360
    @sapphiregaming4360 Před 10 měsíci

    How did you make the animation curve for Cl vs alpha? Need a bit help with that. Please guide me with the steps.

    • @Vazgriz
      @Vazgriz  Před 10 měsíci

      I used airfoiltools.com to find the data for the F-15's wing (which is a symmetrical wing). Then I plotted the data in Excel.

  • @immortaldev1489
    @immortaldev1489 Před 11 měsíci

    how would you implement negative stability and FLCS?

  • @RecHorrors
    @RecHorrors Před 10 měsíci

    Thanks man! But my one problem is that none of the inputs work even when I plug in my controller

  • @valentinstudio3334
    @valentinstudio3334 Před 4 měsíci

    One downside though, I seem to be able to go straight up, and after around 3 minutes of climbing I'm still going at 85% of my max speed and it's not going any lower
    In reality you could not climb completely vertically for an infinite amount of time, you would lose a lot of velocity very fast

  • @ceriumin3227
    @ceriumin3227 Před rokem +1

    I've discovered an issue where the plane seems to go out of control when going very fast

  • @GabrielxC
    @GabrielxC Před 8 měsíci +1

    How did you made the camera?

  • @fuzzybloodpc9291
    @fuzzybloodpc9291 Před 8 měsíci

    20:54 Average Delta wing

  • @skyblox-eo5se
    @skyblox-eo5se Před rokem

    Make a thrust Vectoring plane plzzz

  • @GreekRussian367
    @GreekRussian367 Před 2 měsíci

    Im having the problem that I was going to change the input to mouse and keyboard, and I changed it all in the "PlayerInput", but it does not work, I tried to debug it but nothings working. Is it using a different input system? help.

  • @mrcelsius2928
    @mrcelsius2928 Před 9 měsíci

    Damn, dcs getting called nerdy. Wow.

  • @a.s.b.
    @a.s.b. Před rokem +1

    would you mind if i used code from this in a game i am making? it will be free if i post it anywhere.

    • @Vazgriz
      @Vazgriz  Před rokem +1

      The github repo is MIT licensed. So there are very few restrictions and I don't mind.

  • @yahiagaming7053
    @yahiagaming7053 Před rokem +1

    The code is all red maybe it’s because I’m using C# I thought that was what you were using 😅

  • @TheOfficalCorrieR2
    @TheOfficalCorrieR2 Před 3 měsíci

    @Vazgriz How do I land the plane? it keeps crashing.

  • @travisco13
    @travisco13 Před rokem +1

    I fell in love with you

  • @newsystem3667
    @newsystem3667 Před 10 měsíci

    How did you avoid gimbal lock?

  • @abizair1832
    @abizair1832 Před rokem

    How do you extract the AoA value? I tried to use "rb..velocity.direction" but it doesn't work somehow...

    • @Vazgriz
      @Vazgriz  Před rokem

      AOA is the angle between the velocity and the direction the plane is facing. I use Atan2 to extract the velocity at 8:04

    • @abizair1832
      @abizair1832 Před rokem

      @@Vazgriz Problem is, there's no variables like LocalVelocity.y and such in my Unity (v4.3)

    • @Vazgriz
      @Vazgriz  Před rokem +1

      Right, LocalVelocity is something I calculate in my code. It's the rigidbody velocity translated into the rigidbody's local space.

  • @epich307
    @epich307 Před 3 měsíci

    where were this tutorial when I needed?

  • @DjblackgameBlackgamers
    @DjblackgameBlackgamers Před 3 měsíci

    I'm trying to remake this on UE5 but nothing works on UE someone can help?

  • @greggory7655
    @greggory7655 Před rokem +1

    Note: "AngleOfAttackYaw" is more professionally called Angle Of Slip. Hope this helps!

  • @Eternal_Rest_Official
    @Eternal_Rest_Official Před 6 měsíci

    Is it possible to do this in unreal engine or is it only for unity?

    • @Vazgriz
      @Vazgriz  Před 6 měsíci

      All of the principles of flight can be translated to any game engine. The C# code cannot be used in Unreal of course.

    • @Eternal_Rest_Official
      @Eternal_Rest_Official Před 6 měsíci

      Oh that makes sense, Would you be able to make a tutorial like this on unreal engine Cause i dont know how to make a G Limiter like you did aswell as physics being made well@@Vazgriz

  • @andreicristianfigula9961

    MOOORRREEEEE PPPLLLLSSSSS

  • @generalindominus2722
    @generalindominus2722 Před rokem

    I dont understand why Utilities is without context but I don't see you declare it in the codes

    • @Vazgriz
      @Vazgriz  Před rokem

      The Utilities class is defined in Utilities.cs in the Github repo. It contains some math functions that are fairly simple and used in multiple places in the code.

  • @daxmiller2670
    @daxmiller2670 Před 4 měsíci

    is this able to translate to unreal engine ?

  • @kurisuevergarden8575
    @kurisuevergarden8575 Před rokem

    Preventing turns that would injure the pilot...
    *continues to crash because of lacking turning radius

    • @vast634
      @vast634 Před rokem

      I wonder if military planes remove that limit if a plane is about to crash. (as indicated by the radar altimeter)

  • @Daddyidkwhy
    @Daddyidkwhy Před rokem +1

    Hi the f15 does not show up for some reason i dont know why but can someone help me?
    And wich version is he using

    • @Vazgriz
      @Vazgriz  Před rokem

      You need to download the files using git LFS, otherwise the project will be corrupted. This project was made with Unity 2021.3.10f1

    • @Daddyidkwhy
      @Daddyidkwhy Před rokem

      @@Vazgriz Ok thanks

    • @Daddyidkwhy
      @Daddyidkwhy Před rokem

      @@Vazgriz Zip or Other thing

  • @reverse1895
    @reverse1895 Před 3 měsíci

    does this still work? I tried downloading the project but the prefabs dont work and same with the terrain

    • @Vazgriz
      @Vazgriz  Před 3 měsíci

      Did you download it with Git LFS?

    • @reverse1895
      @reverse1895 Před 3 měsíci

      @@Vazgriz no i didn't how do i do that
      edit: Nevermind i got it

  • @choppedandspewed
    @choppedandspewed Před rokem +1

    can I make a PR that implements redding out/exploding pilot heads?

  • @swastikdas9687
    @swastikdas9687 Před 9 měsíci +1

    how to download!!

  • @Nurfishlol
    @Nurfishlol Před rokem

    Bro if left wing is going up its going to right but ur plane is left