Creating a Flight Simulator in Unity3D (Part 1)
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
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!
Guy has 3k subs, the video was barely an hour old when you commented. Stop being so dramatic
Then share this video on your social media.
bad intro lol
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.
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!
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
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.
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
Found this from reddit. Your tutorial blog posts are awesome!
This is so easy to follow. You did a great job keeping the material clear and concise. Great work!
You call me nerdy for playing dcs, yet here you are coding.
Thank you so much for such detailed but clear presentation.
Thank you man, I have been trying to make a flying simulator for so long, this tutorial is so helpful.
I'm amazed! Thank you for this piece of art!
you are my professor.... idk why you did this and made it open source, bravo! many many respect!
even if dont use unity, your explanation skills amaze me, it is super interesting and it made me think about learning unity. Cool video
THE PHYSICS SUBSTEP IS GENIUS!!! SOLVED MY PROBLEM ON A INDIVIDUAL SURFACE SIMUATION!
This is incredible. Thank you so much for releasing the source code
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
thanks for the tutorial, it was really helpful. I am new to Unity3D and C# and I wish to learn more from you.
Awesome! So well explained, thanks!
Great video! Looking forward for the next part.
Visuals are very helpful and quick. Nice
As a game developer I'm impressed on how you did this!
Very nice overview on the calculated forces and flight mechanics in general. Maybe you can add keyboard+mouse control to your demo too.
Very interesting introductory video with awesome animations! gg.
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
I've wanted to do this for a long time.
THANKS
🐦
Loved the video. You have big potential boy
This is really awesome tutorial video great work man.
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 :)
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).
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".
@@GonziHere how did you go about implementing Fly By Wire in unity? seems interesting to try
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.
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.
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??
Thank you for sharing this useful information.
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!
Great video, commenting for the algorithm!
Superb work on this!
super great I will try in MSPhysics too.
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
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
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?
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.
Great tut, thanks.
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!
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
19:06 Absolute perfection!
Yeah, I've totally lost it there :D :D :D
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
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
great vid man :D :)
Killer. Keep going bro
best line of the whole video: "Dont ask me why, because I discovered it by accident"
Over G fighters was a solid midline between sim and arcade
I like how the plane just turns into smoke
Great work.
You could get Rho based on player altitude by using the perfect gas law.
Nah, you need both temperature and pressure for that. Can just use a lookup table or a basic scale height equation though
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?
vert underrated
Amazing
Hey if you like tiny combat arena you should check out Strike Fighters 2
Thank you
1st sentence got me dieing - I like to play flight sims as Ace combat and project wingman 💀💀💀
You can make it so that the pilot can endure higher G-Force for a short amount of time.
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.
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).
Bro... The flap are inverted normally if you want to create a up lift you make the flap point down
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?
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.
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.
Can you do tutorial videos about the tank you uploaded on CZcams?
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
8:32 how do you add specific keybinds for the throttle?
Please keep going, subbed and loving it!!! Please show us throttle, gears, etc etc
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
0:42 dcs also has insane storage space for my tiny ass laptop
if you think of the grind as fun playime, not agonizing grinding, war thunder is quite fun
Awesome! Can you use the pc keyboard to play this in Unity?
No. Only gamepad control is implemented. You can of course download the project and implement it yourself.
I bought a controller just for this. The experience is so much better.
@@Vazgriz can you help me implement keyboard input
How did you make the animation curve for Cl vs alpha? Need a bit help with that. Please guide me with the steps.
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.
how would you implement negative stability and FLCS?
Thanks man! But my one problem is that none of the inputs work even when I plug in my controller
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
I've discovered an issue where the plane seems to go out of control when going very fast
How did you made the camera?
20:54 Average Delta wing
Make a thrust Vectoring plane plzzz
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.
Damn, dcs getting called nerdy. Wow.
would you mind if i used code from this in a game i am making? it will be free if i post it anywhere.
The github repo is MIT licensed. So there are very few restrictions and I don't mind.
The code is all red maybe it’s because I’m using C# I thought that was what you were using 😅
and what coding language is this ❤
@Vazgriz How do I land the plane? it keeps crashing.
I fell in love with you
How did you avoid gimbal lock?
How do you extract the AoA value? I tried to use "rb..velocity.direction" but it doesn't work somehow...
AOA is the angle between the velocity and the direction the plane is facing. I use Atan2 to extract the velocity at 8:04
@@Vazgriz Problem is, there's no variables like LocalVelocity.y and such in my Unity (v4.3)
Right, LocalVelocity is something I calculate in my code. It's the rigidbody velocity translated into the rigidbody's local space.
where were this tutorial when I needed?
I'm trying to remake this on UE5 but nothing works on UE someone can help?
Note: "AngleOfAttackYaw" is more professionally called Angle Of Slip. Hope this helps!
Is it possible to do this in unreal engine or is it only for unity?
All of the principles of flight can be translated to any game engine. The C# code cannot be used in Unreal of course.
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
MOOORRREEEEE PPPLLLLSSSSS
I dont understand why Utilities is without context but I don't see you declare it in the codes
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.
is this able to translate to unreal engine ?
Preventing turns that would injure the pilot...
*continues to crash because of lacking turning radius
I wonder if military planes remove that limit if a plane is about to crash. (as indicated by the radar altimeter)
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
You need to download the files using git LFS, otherwise the project will be corrupted. This project was made with Unity 2021.3.10f1
@@Vazgriz Ok thanks
@@Vazgriz Zip or Other thing
does this still work? I tried downloading the project but the prefabs dont work and same with the terrain
Did you download it with Git LFS?
@@Vazgriz no i didn't how do i do that
edit: Nevermind i got it
can I make a PR that implements redding out/exploding pilot heads?
how to download!!
Bro if left wing is going up its going to right but ur plane is left