You can break it in two ways. Kochi-mangalore-hampi or Kochi-mangalore-hampi. You can find local as well as private overnight buses to hampi. If you choose train then head to Hospet, from there it's just 15km to hampi.
Catch a train to Mangalore from Kochi. From Mangalore, you have a train, a flight and many buses to Hubballi. From Hubballi lot of buses are there to Hospet / Hampi. Best option is to fly to Bengaluru or Hyderabad from Kochi. From these two cities daily flight is there by Trujet to Jindal Vidyanagar airport (VDY) which is just 37 KMs from Hampi. From airport to Hampi you can hire a cab.