How would I script an airplane?

Hello there. My question is how would I go about scripting an airplane? I know this is a pretty big question as this question can have sub-questions, like “Do you mean the engine of the plane?” or “Do you mean the wheels of the plane?” What I am trying to find out is how to script the plane to fly in general (Pitch, Yaw, Roll, and maybe Throttle.)

Something that I guess that would be included are BodyMovers, because a lot of designs that fly have those. I will try to separate each question into it’s own paragraph.

My first question is what would be the best way to make the airplane move. Most popular choice (of what I have seen) are BodyMovers. CFrames might be used too (I hardly believe so because it is controlled by the player and it can vary due to speed and altitude and all that, but I might be wrong), and lastly, TweenService (I do not believe TweenService would be a good idea). I might not have mentioned a way that you could represent that, and if you know I way that I can create the movement by using another technique and it works better than those listed, then please tell me. Also, please list the type of seat that I would be best to use.

Adding to the above paragraph, I am want the controls to be controlled by keyboard (W/S - Pitch, A/D - Roll, Q/E - Yaw) or mouse (Wherever the mouse points is where the plane will face, Q/E - Yaw), but I am sure that if I can get either the keyboard to work or the mouse, I will be able to figure out how to implement that on the other control type.

My second question is physics. If the airplane is made using BodyMovers, does it have airplane physics by default? If not, would I implement the physics by myself (if heading straight up, then the plane is most likely going to stall, calculating angles and velocity)? If I do have to implement the physics by myself, I would create another topic for that, so the only thing that I want to know is if there are physics by default or if I need to implement them.

I know this topic turned out very long, and I apologize for that. If I posted this in the wrong category, please fell free to tell me. If this topic should be separated into different parts, please inform me about that too. If you do have an answer to any of my questions, feel free to reply to this topic. Any example code (nothing complicated) would be appreciated too. If there are basic models (like a single object that acts like an airplane) that you could show me so I could get an example, then that would be awesome. Thank you for your time and effort.

5 Likes

Airplanes are pretty complicated to program, as there isn’t any sort of wind simulation built into the Physics Engine, so you’ll need to produce component forces for each (Drag, lift, etc) to actually get a reasonable simulation.

One person who is quite famous for their open source airplane mechanics is @Crazyman32 - I’m sure they’d have something to input here.

2 Likes

Thank you for your reply. Physics are something that I would consider later, after I could get a working plane. I am probably going to use these scripts in an airline group, so physics like wind would not be needed. Again, thank you for your reply.

The problem is that you can’t actually get a “working plane” without simulating the physics. I’m not referring to accurate wind current simulations, but actually producing drag and lift.

1 Like

I am aware of that. I will for sure include plane physics, I just might not include physics that are not really required, like wind direction and speed. Drag and lift will for sure need to be included, but wind direction and speed will probably not be included as they will be static. For right now, if I could get a part that has a seat on it to be able to fly, then I will be satisfied with that. If physics are required for the plane to do basic functions (forwards/backwards, up/down, right/left, tilt and rotate) then I’ll script the physics at the same time with the basic functions, but if they are not required for basic functioning, then I’ll add them after I get the basic functioning down.

Like you mentioned, this is a big question to answer. For things like this, just to get started, I’d actually recommend grabbing a free-model airplane (I’m sure there are many out there) and learning how they function from that. You might find a few neat methods to how their creators approached some possible aspects you listed. A lot of times, learning from free-models/open source creations are a great way to jump-start your own approaches.

6 Likes