Bats are intuitive physicists, understanding instinctively the way sound moves through space. Not only do they listen keenly to their environments, but they also send out ultrasonic chirps to help them localize prey; the time it takes for a chirp to come back correlates with the distance of the object. This remarkable use of sound makes bats “the perfect system” for researchers like Melville Wohlgemuth, a neuroscientist at Johns Hopkins University, to study hearing.

So when Wohlgemuth noticed that the bats in his lab were doing something weird, he knew it had to have a purpose. Specifically, his bats were cocking their heads and waggling their ears in an adorable way that made him think of his pet pug back at home, Willie Nelson. Unlike Willie Nelson, however, Wohlgemuth knew the bats couldn’t just be trying to look cute to get their supper. So what were they doing?

To find out, he needed to design an experiment as intricate as a bat’s sound system—one that required amenable bats, video game cameras and some rather unlucky mealworms. “Pretty astonishing,” is how Rickye Heffner, a psychologist at the University of Toledo who specializes in the evolution of hearing, describes Wohlgemuth’s research design. “It’s almost a tour de force demonstration of how it’s all working.”

First, the experiment had to take place in total darkness to ensure that the bats relied only on echolocation. (Contrary to popular belief, bats are not blind—they just tend to have poorer vision.) Wohlgemuth and colleagues used infrared motion-capture cameras—the same kind gamers use—to film each subtle movement without adding pesky visible light. Meanwhile, ultrasonic microphones recorded their high-pitched chirps.

Next, he had to get the darned things to sit still. After collecting dozens of big brown bats from a series of filthy Bethesda attics, he began training them to sit patiently on a platform while dinner came to them. Not all bats complied, but after two weeks, many became “really chill” around him. It helped that he rewarded their efforts with a juicy grub, Pavlovian-style. “I’m much better at training bats than I am at training dogs,” he says.

Finally, Wohlgemuth developed a fishing line-and-pulley system to deliver mealworms to his bats. When he ran the experiment, he found that the more abruptly the insects moved, the more the bats cocked and waggled their ears in an effort to localize their prey. “When the target got closer, the ears moved apart, and when the target was further away, the ears moved closer together,” says Cindy Moss, a neuroscientist who runs Wohlgemuth’s lab and co-authored the paper.

Cats, dogs and even humans pivot their ears to orient themselves toward sound. But this was a bit more sophisticated. By rapidly waggling their ears just after they chirped, bats tracked the tiny change in frequency—think the sound of a car speeding past—as the mealworms moved in one direction or the other. With each movement, the bat took another “snapshot” of the sound, stringing them together to create the acoustic version of a panoramic photo.

“The movement of the ear is like getting different perspectives on the same sound,” says Wohlgemuth, who reported his findings with Moss in the journal PLOS Biology in September.

The study is the first to detail how these bats turn echolocation signals into a 3-D image of moving prey and could provide practical tips for engineers. Wohlgemuth is in talks with researchers at the University of Maryland who are hoping to design a “smart” cane for blind people that hears an obstacle before they reach it. He's also collaborating with engineers in Denmark twho want to develop an “eared” drone mounted with microphone arrays.

Less practically, this kind of research might help answer philosopher Thomas Nagel’s timeless question: What is it like to be a bat? After all, says Moss, “everything that we see in their behavior reflects something going on in the brain."