Determining what causes wind direction in the dynamic troposphere of the Earth is not as straightforward as it may seem. Despite this, scientists have a good grasp of the three primary factors that come together to create both wind speed and direction. Certain forces play bigger roles depending on geographic scale and area. But regardless of location and scale, those three forces are the influences behind a change in wind direction.
Pressure Causes Change in Wind Direction
Blowing from high to low pressure, air always attempts to balance out the pressure levels. A high-pressure system next to a low-pressure system will cause wind direction to flow clockwise and outward toward a low-pressure system. The low-pressure system is what causes air direction to flow counterclockwise and inward. This is also referred to as a cyclonic flow and is one of the ingredients that can come together to create a tropical cyclone, hurricane or typhoon (all different names for the same weather phenomenon).
If air is always trying to balance out pressure differences, why doesn't the wind direction flow directly from high to low? This phenomenon is the Coriolis effect, defined by the National Weather Service as allowing the "calculation of the apparent effects on moving bodies when viewed from a rotating Earth." It is not really a force, though its actions resemble one. Describing its effect on weather and wind direction is commonly done using the merry-go-round example. Imagine looking down on two children sitting on a counterclockwise-spinning merry-go-round, tossing a ball back and forth. Looking down, it appears the ball is moving in a straight line. The children would say it seems as if a force is deflecting the ball to the right of where it is thrown. The cause of wind direction deflecting is the same effect and is due to the Earth spinning counterclockwise below the wind. Greater Coriolis effect is seen closer to the pole regions, and in the southern hemisphere this deflection is to the left. Extremely small scales diminish the Coriolis effect, but it is a huge factor in mid-latitude systems' wind direction. Accelerating speed will increase deflection.
Friction and Wind Direction
The final cause of wind direction is friction. Surface-level winds are mostly influenced by friction, as this is where wind encounters varying surfaces. If the wind blows toward a building, it must go through a change in direction. It could rise above the building or go around it in either direction, but the presence of the building will cause a wind direction change. Slowing down of winds by a rougher surface will also decrease Coriolis deflection, and acceleration over a smoother surface will cause the opposite.