You have all math there, so copy logic over to your project with pawn control rotation.
I put all in macros and somewhat commented them, should not be hard.
Pawn rotation control and all that had some niuances to make it working and i forgot how to setup that correctly in unreal.