SimpleWings icon indicating copy to clipboard operation
SimpleWings copied to clipboard

Wind

Open andygilbert29 opened this issue 5 years ago • 8 comments

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

andygilbert29 avatar Oct 16 '19 10:10 andygilbert29

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?

VikingPingvin avatar Oct 24 '19 12:10 VikingPingvin

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?)

andygilbert29 avatar Oct 24 '19 13:10 andygilbert29

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.

VikingPingvin avatar Oct 29 '19 19:10 VikingPingvin

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.

brihernandez avatar May 07 '20 12:05 brihernandez

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

andygilbert29 avatar May 07 '20 13:05 andygilbert29

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

brihernandez avatar May 07 '20 13:05 brihernandez

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

andygilbert29 avatar May 07 '20 13:05 andygilbert29

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

RyanJiff avatar Jun 01 '23 08:06 RyanJiff