If the x,z things are (mathematical) vectors, I use a vector object instead of independent variables, so I would either do
A.something = B.something
A.mSomething = B.mSomething
or
for(int i=0;i<2;++i)
{
A = B;
}
Both of which reduce chance for manual errors when doing repetitive stuff.
I guess if you have an y component and want to skip that, and its a common thing, you can write a special function for that:
A.setXZ(B)
So whenever I do anything related to vectors/matrices I use loops instead of manually handling every component. It also usually generalizes to any number of dimensions if I care about that.
For other things, if you cant make the type checker detect the errors, see if you can change your naming conventions to highlight them better. mX instead of mx might be more visible. Also consider adding comments that state what must be done, before actually writing the code. That will force you to think a bit more and also remind if you forget something while writing it out.
In the case of using current_location instead of new_location, perhaps you can limit the scope of variables even more (such as by using anonymous scope), so theres less potential wrong choices to make. Some people might also make variables useless by setting some garbage value just after the last use (like setting pointers to nullptr after delete).
Then theres tools like assertions and unit tests, which are also a bit like comments, except theyre actually checked. People really care about writing safe and correct code, you could even look into fields where its extra-critical and see what they do.