How Would i make a tower tilt

i am trying to achive this:


pay attention to the tilting

and i got this:

it just flops around.
i have made something but not exactly what i desire here is my math logic:
image

i need serious help on this soo please.

i got this now:

just need to figure out how to make it move to the -x and the -z
btw new code if you can help: