The magnificently long, spined tails of ancient dinosaurs are unlike anything that's alive today. New research suggests that they elegantly swished side-to-side while their owners walked, and enthusiastically wagged when they ran.

It took around 80 million years for the bird lineage of dinosaurs to lose such lengthy tails, which they did in line with significant changes to body proportions and posture. The fact long tails stuck around so stubbornly suggests they were important for these animals.

But without living examples, how exactly the tails of dinosaurs contributed to their ancient existence isn't fully understood; dinosaur tails have previously been examined for their potential in antipredator defense, within-species communications and also their role in balance and swimming.

New modelling shows they likely played a key function in dinosaur locomotion beyond merely as a counterweight to their upright pose.

"When I first saw the simulation results I was very surprised," said paleontologist Peter Bishop, currently at Queensland Museum.

The simulations revealed that both the tail and neck of the non-avian theropods (the group that includes Tyrannosaurus rex and velociraptors) they modelled, swished side-to-side.

Applying physical and biological parameters worked out from studying existing species, Bishop and colleagues used a whole-body approach with anatomic and muscle models to create detailed 3D models of dynamic animal walking behaviors, constrained by the underlying physics of its biological system.

They tested the model's accuracy by simulating the movements of a currently living bird species called tinamou (Eudromia elegans) – a ground-nesting, South American shrubland bird.

"The simulations spontaneously generated walking and running gaits that had a strong kinematic and kinetic match to empirical observations," the team wrote in their paper.

The model also predicted these birds could run as fast as 2.62 m/s, which is in line with what we know about tinamou.

So, they developed a simulation of Coelophysis bauri – a small carnivorous theropod that hunted insects, lizards and babies of ancient crocodile ancestors around 220 million years ago. These animals had hollow bones and were sleek and slim like greyhounds, allowing them to be light, agile and likely very fast. They were up to 3 meters long (9.8 ft) and weighed around 15 kilograms.

Previous locomotion models have treated the body segments along the animal's length as a single rigid entity, and tail as a counterbalance to its front end, but the researchers incorporated axial movements to see how "whole-animal movement interacted with morphology, neuromuscular control and performance."

"After running a range of further simulations making the tails heavier, lighter and even no tail at all, we were able to conclusively demonstrate that the tail wagging was a means of controlling angular momentum throughout their gait," explained Bishop.

By swishing side-to-side, C. bauri's tail regulated angular momentum (the amount of rotational motion) for the animal's entire body by acting as an inertial damper. It kept this rotational motion within a limited range.

"Essentially, our findings show that dinosaurs like Tyrannosaurus and Velociraptor wagged their tails from side to side when they ran, which helped them stay balanced," said Bishop.

The model showed a speed limitation beyond 5.7 m/s, which is a fast running gait for this species. It may be a slight underestimate though, as foot-ground reaction forces were not entirely accurate, the team notes. There were also a few other areas that showed discrepancies between the initial model and the real bird, including a more upright hip posture.

But the model revealed C. bauri's tail movements appear to have been coordinated with other body movements in a way that minimized the muscular effort required.

Running a tail-free simulation showed that while the tailless model dinosaur was able to adjust its movement patterns to compensate for this lack of inertial damping, it increased the muscle effort required by 18 percent, demonstrating that dinosaur tails had a pivotal role beyond being a simple counterweight.

"This research gives us greater insight into how dinosaurs moved and may very well change the way we see dinosaurs depicted in films such as Jurassic Park in the future," said Queensland Museum Network CEO Jim Thompson.

This research was published in Science Advances.