Comet is a bright object in space that has a tail of gas and dust. The story of origin of comets in Hindu tradition is associated with Shiva destroying the flying cities Tripuri. Legend has it that a powerful demon named Tripuri or Tripurasura built three impregnable cities of gold, silver and iron with the blessing of Shiva. The demon became so powerful and his inflated ego knew no bounds and started attacking and tormenting humans and demi gods (devas) by flying on Tripuri.
Brahma and Vishnu failed to contain Tripurasura who was armed with several boons from Shiva. Finally, the task of annihilating the demon fell on Shiva. The flying cities could be destroyed only with a single arrow. For this the cities had to align in a straight line.
Once in a while the cities aligned in a straight line for a split of a second. Shiva was the only archer who could destroy the cities.
For this purpose, Vishnu himself turned into the fiery arrow – Vishnu Shastra.
Shiva chased the three cities through space and waited for the right moment. After three days of chasing the cities aligned in a straight line for a split of a second and Shiva shot the arrow Vishnu Shastra and destroyed the three flying cities – Tripuri.
The remains of the cities floated in space and became comets.