I’m new to unity, and have been appointed to script a game design. What we are looking at doing is controlling a plane, but what i was wondering if it was easy enough to apply a wind effect (With a controllable variable) to an object?
Sorry if this is a real stupid question, i just though i should ask before we go with this idea.
It all depends on what the wind should do. The above approach will push your plane in a certain direction, but that direction will always stay the same. Since wind (air) is a fluid, you could dive into some fluid mechanics to make it very interesting. Take an aerodynamic properties such as profile drag, for example, which would give you a nice non-linear distribution of drag forces, making controlling the plane harder.
So, how exactly should the wind affect the plane? If you know that, then you can determine what kind of approach you need.
The wind will be affecting the plane differently on each level (Increasing/Decreasing in different directions). Basically giving it drag and making it slower and harder into the headwind, and fast when in the tailwind. Also applying to other obsticles such as birds etc.
Ive drawn up a (REALLY) basic illustration just to prove my point a bit better.
And here is a simple example game that applies the same basic principles.
The wind is basically just a force, although you might want the plane to get blown more if the wings are facing flat to the wind. You can do this using the dot product of the plane’s upward direction and the direction of the wind. If you use a normalised vector for the direction of the wind, then something like:-
var faceOn: float = Mathf.Abs(Vector3.Dot(transform.up, windDirection));
Will give you a value from 0 to 1 indicating how strongly the plane is facing the wind. You can use that as a parameter to Mathf.Lerp (or whatever) to vary the strength of the wind’s effect on the plane.
I am working on a flight sim for a drone and I want to apply wind correctly. If I Apply a force to the rigidbody, the plane turns in the direction opposite the force. In reality the heading should NOT CHANGE, but it should slide along the vector of the wind. I’ve tried applying a force with rb.AddForce(force,mode) - experimenting with all modes.
I also have ADDED to the velocities of the rb.Velocity vector using the wind as a unit vector * the windspeed. THIS seems to have the same effect. I am using Unity FS for physics, but I’m applying directly to the rigidbody, so I didn’t think it would change the physics calculation done in UnityFS, but maybe it does.
Any opinions or thoughts about how to apply the wind so that the heading stays unchanged?