Wind
Some components can be animated by wind. For instance particle effects and ropes will react to wind. Usually these animations are for decorative purposes.
Wind is implemented as a world module. Thus, it is possible to have different wind system implementations, and choose the most suitable for each scene. For example, one system may do a full volumetric fluid simulation, whereas another does not.
You instantiate a specific wind system by adding the respective component to a scene. At this time, Plasma only ships with a basic implementation. You instantiate it with the simple wind component. As long as there is no such component in a scene, there won't be any wind.
Querying Wind Values
At runtime you query the wind value by location. First you need to retrieve the wind world module:
Make sure to check the pointer for nullptr
, which happens when there is no wind system set up for a scene.
Then the wind can be queried by location:
This returns a vector with the direction and strength of the wind at the queried position.
To react properly to wind, this value must be polled every frame. However, be careful to query only few values. Depending on the active system, this can be a very fast or a rather slow operation. However, usually wind doesn't change drastically within short distances.
Controlling Wind
To add wind locally, have a look at the wind volume components. These can be used both for static wind fields, for example to make a flag blow in the wind nicely, as well as for short lived dynamic effects, such as the shockwave of an explosion.
Affecting Physics Objects
Be aware that wind does not affect any physics objects. Such behavior could be implemented, but it would be difficult to not have a serious performance impact, since it would keep the physics engine constantly busy (usually objects go to sleep when no forces act upon them, but wind would be a constantly active force).
Instead, explosions and such rather use a physics shape query to determine objects in range, and then apply a short impulse to only those objects once. See the area damage component as an example.
Custom Wind Systems
It is possible to write your own wind system. Just implement a new world module, derive it from plWindWorldModuleInterface
and override the GetWindAt()
function. Put your code into a custom engine plugin and also add a custom component type to instantiate your wind world module, and make it configurable.
For inspiration, just have a look at plSimpleWindWorldModule
and plSimpleWindComponent
.