Swarming locusts interact with at least two of their neighbours when aligning themselves in order to march in the same direction, research has found.
As they swarm, locusts tend to move in the same direction as their neighbours but then spontaneously switch direction as a group - behaviour also seen in starlings and fish.
The swarm becomes more stable and has less directional switching as more locusts join the group.
Locust swarms - the eighth plague of Egypt in the Book of Exodus - have devastating impacts on crops and vegetation, which can lead to famine and starvation.
Teams at the Universities of Bath and Warwick say that mathematically modelling the behaviour of swarms could lead to new strategies for controlling or dispersing them.
Dr Kit Yates, from the Department for Mathematical Sciences at the University of Bath, said: "We can describe the locusts' behaviour using quite simple rules and have demonstrated for the first time that locusts have to interact with multiple neighbours in order to swarm in the way they do.
"We already know that animals, including humans, change their behaviour when they are in a crowd, following cues from their peers.
"In the locust study, we found that small groups of locusts are unstable and tend not to march together - a behaviour mimicked in our model.
"With larger groups, the swarms tend to be more stable, with less switching of direction, so rogue individuals travelling in the opposite direction don't have as significant an effect on the behaviour of the whole group.
"A better understanding of how individuals behave in these groups could help us develop new strategies of disrupting swarms.
"Our model could also be applied to other swarming insects such as crickets, which are a major problem in Australia, and even in crowd dynamics of humans."
The team of mathematicians at Bath, in collaboration with the Universities of Warwick and Manchester, analysed the movements of different group sizes of locusts filmed at the University of Adelaide.
They then used the data to study the interactions between individual locusts and create a model that mimicked the collective behaviour of the insects.
Their findings, published in the journal Physical Review E, show for the first time that locusts interact with several of their immediate neighbours when deciding the direction to march.
Previous research by the team found that locusts tend to align themselves with their neighbours so their vulnerable flanks are not exposed to cannibalistic attack.
The mathematical model predicts that locusts are sensitive to external changes in the system, such as wind conditions, which can disrupt interactions between the insects and make the swarm less stable.
Dr Louise Dyson, research fellow at the University of Warwick, said: "This is the first time that it has been possible to quantitatively compare the locust swarming experiment with a mathematical model.
"Our model successfully reproduces the switching behaviour, in which a large group of locusts may collectively move together, only to collectively reverse direction after a period of time.
"We can even predict the average amount of time before a reverse of direction, dependent on the size of the locust group.
"Our model helps us to understand how the individual decisions made by each locust using the information available to them can result in the dynamics we observe in the group as a whole."
During major plagues, swarms can comprise of up to a quarter of a billion locusts, eating their own body weight in food each day.
They can migrate across 20% of the total land surface of the world, wreaking devastation on crops and the livelihoods of farmers.