I don't know what problem you have with the Joints extension solution, but I can assure you that for this purpose, using joints is much easier, faster and reliable than using math, and you would have to use only one block instead of dozens of blocks. On the contrary, If you prefer a math solution for this case, then you are choosing the longest, most complex and problematic way. However, if you want, I can give you the project file of the same example made with mathematics instead of with Joints. In fact, I have it done too, and it works. But due to it has a certain complexity, I will not be able to explain how its mathematical formulas work.

First I did it with math, and although it works well, later I realized that doing it with Joints is much better.