Jump to content

This might not be appropriate. [Making wings work in Unity]


SYRSA

Recommended Posts

But I think it would not hurt to ask the masters who made this great space simulator/game.

I like flying as much as the next guy. And I especially love attaching wings on my spaceplanes. But there is a particular thing that I have pursued for weeks...

KSP runs on the Unity engine, right? KSP led me to this user-friendly game engine. But I have been dying to ask one thing. How in the world did you guys manage to make your wings work? You know, glide. You all have seen this when your spaceplane have crashed into the ground, but a pair of wings have survived and then soared off.

Back on the Unity forums, I have started thread after thread and no one has a clue what I am talking about. I have tried to make my wings work in my Unity project, but they keep failing. How did you manage it? I would be so happy if someone could teach me the ways of the wing. And maybe even repay you (if it is so much of an hassle) with something that I could make, since I'm an artist.

Edited by SYRSA
Added additional info to the title
Link to comment
Share on other sites

Well, the title was pretty appropriate in my opinion. Because I think asking game developers for clues how they managed some things in their game might be borderline copyright infringement.

Link to comment
Share on other sites

I'm sure SOMEONE in our modding community could help you out. Ferram is indeed a mod developer and messes with the aerodynamics a bit so he might know. And if not, there's plenty more people that I'm sure could.

That said, this thread MAY get the attention you're seeking in the add-on forums, so I'll pop it over there. If you don't want it in there I can always move it back.

Link to comment
Share on other sites

Perhaps some code along the lines of "if this object is moving with a velocity vector within X degrees of the object's orientation vector, apply force Y in the direction normal to the wing surface with a magnitude of (lift coefficient times object speed)"?

Link to comment
Share on other sites

To be accurate, this is actually the code I am using:

#pragma strict

var AxisDrag: Vector3;//multiplier

function Update () {

var x: float = rigidbody.velocity.x * AxisDrag.x * -1 * Time.deltaTime;

var y: float = rigidbody.velocity.y * AxisDrag.y * -1 * Time.deltaTime;

var z: float = rigidbody.velocity.z * AxisDrag.z * -1 * Time.deltaTime;

rigidbody.AddForce(x,y,z);

}

The point was to attach this code to a wing, which is just an invisible gameobject (because I already modeled the aircraft itself). And what I hoped this code to do is to have the Y-axis to simulate more drag than any other axis because the Y-axis is the flat side of the wing. But all it did was applying global drag to the wing no matter how I angeled it. I even dropped the wing from mid air and it didn't even glide off to one side. It just slowly descended down in a straight line.

Link to comment
Share on other sites

This is not a lift vector for sure. Remember that a wing generates two forces : one thats upwards called lift and another thats backwards that is drag.

So lift is perpendicular to the velocity vector, and drag is opposed.

So, if your velocity is along x, then your drag is along -x and your lift along z, and there is no force on y.

Looking at your code, you got the drag part, but not the lift part, so add the lift compound and it should work. easy as pie.

also, you dont need to make a separate invisible gameobject, you can just add these forces to the object you use already.

edit:

You need to think carefully to where you apply those two forces, in ksp, lift and drag of the wing are both applied to the center of mass of the wing, thats why it can fly by itself! In reality, the center of mass, lift and drag are at different positions, this is why if you rip off a plane's wing and throw it it wont fly, while it does in ksp!

Edited by earth
Link to comment
Share on other sites

cool video! From what ive seen in the video, i dont think you even need to apply several distinct forces, unless you want to simulate things like stall and all. do you know how to calculate a wings lift force?

I can teach you ferram's approach

edit : did you read my post?

Link to comment
Share on other sites

i have no advice to offer but liked the video. sorry if thats not apropriate to post here just wanted to say that. all the programming stuff is way over my head. would love to learn it but it seems so complicated. i just use the mods. how did you learn it if you dont mind me asking?

Link to comment
Share on other sites

I have a fellow coder who knows what to do when it comes to Javascript. And he likes to work with me to make stuff happen, in this case, make the wings (white disks) provide lift. So he would know a thing or 2 if anyone have any ideas for him. And yes, earth. Teaching us about ferram's approach would be nice. I have a livestream (if you are interested) up at the moment at: http://sv.justin.tv/syrsa

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...