Welcome to the forum, Gaogier. That is a good question.
Since you mention Charles and William I presume you are referring to the British queen. As a matter of fact, she is not "the (only) queen" at the moment, as a queen also occupies the throne of Denmark.
As it stands now, the rules of succession in all hereditary European monarchies are determined by two essential principles. As you stated, the first is the rule that birth order determines precedence. The second is that a child is the heir of their parent (or any other direct ancestor), and upon the death of a parent, his or her rights to the throne are transferred to his or her descendant(s).
Thus, if Charles dies while he is the heir to the throne, his dynastic rights as the oldest son pass to his own oldest son William, who will inherit the throne as if he himself were the oldest son of Queen Elizabeth.
I am not sure how long this system has been in place in the UK, but I recommend researching the laws of property inheritance in England as they are the foundation of the laws of succession to the British crown.
There is a thread dedicated to British line of succession here:
https://www.theroyalforums.com/forums/f23/line-of-succession-to-the-british-throne-44513.html
No, not always. As with much of British common law, the laws of inheritance developed over time.
See this research briefing for information.
The bill was passed in 2013 but only came into force in 2015.