Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wind #8

Open
andygilbert29 opened this issue Oct 16, 2019 · 8 comments
Open

Wind #8

andygilbert29 opened this issue Oct 16, 2019 · 8 comments

Comments

@andygilbert29
Copy link

Hi, I have been trying now for a while to add "wind" to this and failed miserably.

I was wondering if this is something you could do easily?

Ideally I want to set a wind vector (direction & speed) and it effect the plane or individual airfoils. (relative velocity and the wind force)

Thanks

@VikingPingvin
Copy link

Hi, I have been trying now for a while to add "wind" to this and failed miserably.

I was wondering if this is something you could do easily?

Ideally I want to set a wind vector (direction & speed) and it effect the plane or individual airfoils. (relative velocity and the wind force)

Thanks

I believe you can easily add external wind effects by adding a vector3 to the local velocity.
Try modifying SimpleWing.cs line 37 like that?

@andygilbert29
Copy link
Author

andygilbert29 commented Oct 24, 2019

Hi, I have been trying now for a while to add "wind" to this and failed miserably.
I was wondering if this is something you could do easily?
Ideally I want to set a wind vector (direction & speed) and it effect the plane or individual airfoils. (relative velocity and the wind force)
Thanks

I believe you can easily add external wind effects by adding a vector3 to the local velocity.
Try modifying SimpleWing.cs line 37 like that?

Hi, thanks for your help, however i'm not so sure its that simple. Line 37 is used only for getting the AOA for display purposes (correct me if im wrong?)

@VikingPingvin
Copy link

Hi, I have been trying now for a while to add "wind" to this and failed miserably.
I was wondering if this is something you could do easily?
Ideally I want to set a wind vector (direction & speed) and it effect the plane or individual airfoils. (relative velocity and the wind force)
Thanks

I believe you can easily add external wind effects by adding a vector3 to the local velocity.
Try modifying SimpleWing.cs line 37 like that?

Hi, thanks for your help, however i'm not so sure its that simple. Line 37 is used only for getting the AOA for display purposes (correct me if im wrong?)

Right, my bad. I wanted to write line 104, in fixedUpdate. It works the same.

@brihernandez
Copy link
Owner

Hello! Wind is an implementation specific thing, so I didn't include it in this project, but here's how I add wind in my game.

Replace these lines in FixedUpdate:

Vector3 localVelocity = transform.InverseTransformDirection(rigid.GetPointVelocity(transform.position));
localVelocity.x = 0f;

With something like this:

// Velocity that this wing feels is the velocity at its specific position,
// and any wind that might be coming from outside.
Vector3 worldVelocity = rigid.GetPointVelocity(transform.position);
worldVelocity += -environment.WindVector;

Vector3 localVelocity = transform.InverseTransformDirection(worldVelocity);
localVelocity.x = 0.0f;

In my implementation, environment is a GameObject in the world which controls things like wind and time of day. The WindVector on it is the direction that the wind is blowing. Wind for wings is weird, because from the wing's perspective it can't tell the difference between wind and just moving through the air normally, so by adding the wind's velocity to the velocity the wing already has, you're simulating that effect per-wing, which is going to be more accurate than applying a velocity to the entire plane.

@andygilbert29
Copy link
Author

Hi, thank you. I am literally working on my project which uses simple wings in, so great timing as I still haven't got back around to implementing wind. I had several attempts and got close, similar to what you have suggested but not exactly so looking forward to trying it.

Am i correct in saying that this will add the wind velocity to each wing which will effect its lift/drag ETC. But will this actually add the forces to the overall plane in a manner that will for instance make the aircraft crab with a side wind?

Thanks

@brihernandez
Copy link
Owner

wind velocity to each wing which will effect its lift/drag ETC

Yes. The important thing is that it affects the lift and drag accordingly, which will generate unusual forces that will naturally cause the plane to crab into the wind since that's just how the physics works out. The more realistic your arrangement of wings on the plane are, the more realistic an effect you're going to get. E.g. if you have a very large vertical tail that's offset from the center of mass, not only will the plane try to weather vane into the wind, but it'll also induce a rolling moment because of the drag incurred.

Here's a gif of my game flying through wind. The camera is looking at the velocity vector, which is direction where the plane is actually moving.

2020-04-30-17-46-29

@andygilbert29
Copy link
Author

That's great, thank you. Will have a play this afternoon. It really is a great system.

@RyanJiff
Copy link

RyanJiff commented Jun 1, 2023

Hello! Wind is an implementation specific thing, so I didn't include it in this project, but here's how I add wind in my game.

Replace these lines in FixedUpdate:

Vector3 localVelocity = transform.InverseTransformDirection(rigid.GetPointVelocity(transform.position));
localVelocity.x = 0f;

With something like this:

// Velocity that this wing feels is the velocity at its specific position,
// and any wind that might be coming from outside.
Vector3 worldVelocity = rigid.GetPointVelocity(transform.position);
worldVelocity += -environment.WindVector;

Vector3 localVelocity = transform.InverseTransformDirection(worldVelocity);
localVelocity.x = 0.0f;

In my implementation, environment is a GameObject in the world which controls things like wind and time of day. The WindVector on it is the direction that the wind is blowing. Wind for wings is weird, because from the wing's perspective it can't tell the difference between wind and just moving through the air normally, so by adding the wind's velocity to the velocity the wing already has, you're simulating that effect per-wing, which is going to be more accurate than applying a velocity to the entire plane.

3 years later and someone found use for your comment :)
Thank you for your amazing work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants