Wind

Wind is a mechanism in Terraria which influences the movement of various objects, as well as the occurance of and Sandstorms.

Wind speed ranges between 0 to 60 mph. The wind can blow from either the west or east. Informational accessories such as the Weather Radio show the direction the wind is blowing from, not towards (so for example, "25 mph W" means that the wind is blowing 25 mph from the west).

Wind primarily affects things that have no effect on gameplay, such as cloud movement speeds, blizzard and sandstorm background effects, and the animations of the surface of water and trees. However, it occasionally plays a part in how the game plays, such as its effects on Detonating Bubbles and its effects on players afflicted with Mighty Wind. The UFO Mount summoned by the Cosmic Car Key also seems to be slightly pushed by wind, but it is unnoticeable unless firing a weapon that bounces at a corner for a long period of time.

The Windy Day event occurs when the wind speed is 20 mph or higher, and ends when wind speed decreases below 16 mph.

The Weather Radio, Fish Finder, PDA, and Cell Phone all list the wind speed in the upper right corner of the screen.

Functionality
There are two core values in the code that control wind speed: windSpeedCurrent and windSpeedTarget, both of which are updated each tick✅. The speed at which windSpeedCurrent changes is determined by the following formula:

speed = |windSpeedTarget/50 * (1 + rain intensity * 5/9) - windSpeedCurrent/50| * 0.0015;

where windSpeedTarget and windSpeedCurrent are in the mph values used by the game. The game stores both values as float values, where < 0 is eastward wind, and > 0 is westward wind. When a world is created, it will generate with winds up to but not exceeding 20 mph, and a variable windCounter is set to prevent changes for the next 15 - 45 seconds. After this period is over, there are a series of random chances that the wind will increase or decrease by up to a certain amount, which occurs on loop every 15 - 45 seconds (a "gust"). A second counter (extremeWindCounter) decreases by one each time a gust occurs. When it hits zero, it causes an "extreme gust". It is both reset on world generation and when an extreme gust is triggered. When an extreme gust occurs, the target wind speed will dictate how many more gusts it will take for another extreme gust to occur.

Finally, if a gust has flipped the direction of the wind, there is a 66% chance that the target wind speed will flip its direction back to the original direction it was facing in. After all these steps, the target wind speed is capped to 40 mph.

Effects
Wind affects the following:

Furniture
Some furnitures are affected by wind when on the surface and either in front of any of the following walls, or behind no wall at all.

The following furnitures are affected by wind when the above conditions are met.

Mighty Wind

 * Mighty Wind by default will push players mph * 0.0012 pixels per second. If the wind speed is > 25mph, then this value increases by 37%. If the player is falling or jumping, this value increases by 50%. Finally, if the player moves left or right, this value is decreases by 20%, and will be capped at 0.072 pixels per frame.
 * Running into opposing wind with enough speed will cause the player to emit particles similar to the effect of running with Hermes Boots.
 * Moving left or right on a mount while at a stationary height negates the effects of mighty wind.

Trivia
At lower wind speeds, the leaves drop with a lower frequency from trees each tick (5 mph → 1/2000 chance, 10 mph → 1/1000, 15 mph → 1/450, ... 40 mph → 1/50). While the maximum speed is 40mph, however, there is code for cases up to and exceeding 55 mph, with chances being as low as 1/10 each tick.

Scrapped Projectile Physics
In the game code, there is a boolean Main.windPhysics that triggers a feature where projectiles would be affected by wind. As it is disabled, there is no such feature in the game currently. Below is a detailed description of the feature's effects.

Notably, this feature would attempt to disable wind effects on the North Pole, however it is unknown if this was to prevent conflict with existing code or to remove the feature outright.

When the feature is active, all projectiles below, when on the surface, and not stuck in tiles or behind walls, will be affected by wind. This occurs only if they are moving against the current wind direction, or if their x velocity is less than wind mph * 0.36. This will change their x velocity by wind mph * 0.002 pixels per tick, or wind mph * 0.12 pixels per second.

A projectile's x velocity in this state cannot exceed 16, but this limit is never reached as the max possible wind speed, 40 mph, can only push projectiles up to 14.4 pixels per tick.

Functionality
There are two base values the game uses when determining windspeed, "windSpeed" and "windSpeedSet". windSpeedSet is a value set to determine what value windSpeed should gradually change to, but both values are used intermittently throughout the code to affect certain objects. The game takes the following steps to determine windSpeed:


 * If windSpeed is not already equal to windSpeedSet, move it closer by .001
 * Change windSpeedSpeed by a value from -.001 to .001 (-.002 to .002 when night)
 * Cap windSpeedSpeed to -.002 or .002
 * Change windSpeedTemp by windSpeedSpeed (windSpeedSpeed x 2 if raining)
 * Cap windSpeedTemp by
 * Set windSpeedSet to windSpeedTemp
 * Loop

Overall this means that there are stronger wind speeds when it is nighttime and/or raining. However, as sandstorms do not count as rain, sandstorms do not actually cause increased wind speeds. Also notable is that more clouds in the sky means higher potential for higher wind speeds, whether it is raining or not.