Dinosaurs went extinct due to a perfect storm of events, researchers say.

According to a team of scientists at the University of Edinburgh, dinosaurs would have survived if the massive asteroid impact had occurred earlier or later in history.

Researchers say that dinosaurs were already facing the problem of lack of food before the impact. The horned triceratops and duck-billed dinosaurs had already suffered a loss in biodiversity even before the impact, The Guardian reports. Loss of plant-eating dinosaurs meant that larger dinosaurs, too, had fewer animals to eat.

The earth was also experiencing an increase in volcanic activity and temperature changes when the 10km-wide asteroid struck earth in what is now Mexico.

The impact led to tsunamis, wildfires and other environmental changes that further weakened dinosaurs' chances of survival. Only those dinosaurs that could fly survived and became the birds that we know today.

"The dinosaurs were victims of colossal bad luck. Not only did a giant asteroid strike, but it happened at the worst possible time, when their ecosystems were vulnerable. Our new findings help clarify one of the enduring mysteries of science," Dr. Steve Brusatte, of the University of Edinburgh's School of GeoSciences, said in a news release.

Scientists said that had the impact occurred earlier in the history of dinosaurs, then many of the animals would have survived the event as the food supply was robust then. If the impact had occurred later, the dinosaurs would have had time to evolve and probably would have had better chances to avoid extinction.

The latest study included researchers from the University of Oxford, Imperial College London and others. The team updated a catalogue of dinosaur fossils to create a picture of how dinosaurs evolved over the few million years before the asteroid impact. The fossils studied in the current research were mostly from North America. Researchers say that ongoing studies on dinosaurs from Spain and China will lead to better understanding of dinosaurs' lives before the mass extinction.

"There has long been intense scientific debate about the cause of the dinosaur extinction. Although our research suggests that dinosaur communities were particularly vulnerable at the time the asteroid hit, there is nothing to suggest that dinosaurs were doomed to extinction. Without that asteroid, the dinosaurs would probably still be here, and we very probably would not," said Dr. Richard Butler of the School of Geography, Earth and Environmental Sciences at the University of Birmingham.

The study is published in the journal Biological Reviews.