There is no hard and fast "law," especially since not everyone has godparents nor are everyone's grandparents still alive.
I'll oversimplify my answer...
If the parents have a will, they can instruct who should receive custody of the children. If no will is available, then immediate family members are looked at first, such as grandparents of the children or aunts and uncles (siblings of the parents). The answer could even be "no one in the family is capable" so the children are placed up for adoption or in a foster care system.
God Parents are for the main purpose of religious upbringing and only come into play as legal guardians when natural blood relatives are either unable or unavailable to take the children. (By Catholic standards)
By law they go to whomever the parents deem as the legal guardian in a will as long as that person or persons agree to it. It could be a next door neighbor or a long distance relative. It usually is a close family member though.