Under the threat of predation, animals can decrease their level of risk by moving towards other individuals to form compact groups. A significant body of theoretical work has proposed multiple movement rules, varying in complexity, which might underlie this process of aggregation. However, if and how animals use these rules to form compact groups is still not well understood, and how environmental factors affect the use of these rules even less so. Here, we evaluate the success of different movement rules, by comparing their predictions with the movement seen when shoals of guppies (Poecilia reticulata) form under the threat of predation. We repeated the experiment in a turbid environment to assess how the use of the movement rules changed when visual information is reduced. During a simulated predator attack, guppies in clear water used complex rules that took multiple neighbours into account, forming compact groups. In turbid water, the difference between all rule predictions and fish movement paths increased, particularly for complex rules, and the resulting shoals were more fragmented than in clear water. We conclude that guppies are able to use complex rules to form dense aggregations, but that environmental factors can limit their ability to do so.