(CNN) -- Flies always appear to be a step ahead of the swatter. And now scientists believe they know why.
New research shows flies rapidly calculate an escape route once they spot a swatter.
According to new research published in the journal Current Biology, flies have a quick-fire intelligence and are good at planning ahead.
Scientists at the California Institute of Technology (Caltech) filmed experiments using fruit flies and a swatter.
They discovered that flies quickly calculated the location of the threat and an escape plan.
Within 100 milliseconds of spotting the swatter they could move their bodies into a position that allowed an extension of the legs to save them.
Caltech Professor Michael Dickinson, who lead the study, said in the journal that it showed how rapidly a fly's brain processed sensory information.
"We also found that when the fly makes planning movements prior to take-off, it takes into account its body position at the time it first sees the threat," Dickinson said.
"When it first notices an approaching threat, a fly's body might be in any sort of posture depending on what it was doing at the time, like grooming, feeding, walking, or courting. Our experiments showed that the fly somehow 'knows' whether it needs to make large or small postural changes to reach the correct preflight posture."
And Dickinson had some advice on how to successfully swat the lightning limbed insects.
"It is best not to swat at the fly's starting position, but rather to aim a bit forward of that to anticipate where the fly is going to jump when it first sees your swatter," he said.