Math help aligning foot to surface during procedural turn in place

Okay, so I’m working on a Procedural Turn In Place routine in combination with PowerIK. I have it working on flat ground, but I’m struggling with the math trying to get the pitch and roll to align to the surface of the destination location. I’ve gone around and around with this and exhausted my google-foo and was hoping for a life line here.

A couple background notes:

  • My turn in place procedure projects a world transform of where the foot should move to by rotating it’s current world transform by x yaw degrees using the RotateAngleAxis function. This works well on flat surfaces, but the problem is, this doesn’t account for the surface normal on un-even ground which has impacts on the roll and pitch.

  • PowerIK controls the feet transform in the AnimBP when not turning via a Power IK Ground node. The take away here is, at the beginning of any turn in place procedure’s calculation, the foot is guaranteed to be aligned to the surface normal. Another note, when the turn in place procedure finishes, PowerIK takes over again and would transition the foot to align with the surface. Ultimately I’m trying to anticipate a good enough foot rotation such that when PowerIK takes over, there isn’t a noticeable transition.

So I have a correctly surface aligned transform and surface normal of where the foot is, and I have a incorrectly surface aligned (but with correct yaw) and surface normal of where the foot should move to. I just need to figure out how to rotate the target transform to align to the surface. It seems like everything is there, I just need the math to put it together.

I’ve tried a bunch of different things, (what feels like many different ways to do the same thing,) and what I’ve most commonly come across is making a rotator from the atan2 of the surface normal’s values. I believe this gives me something in component space, but just can’t seem to apply it to world space. Also it doesn’t account for Yaw. It’s like I need to reconcile the target transform’s yaw with the target location’s surface normal with the current foot’s pitch/yaw (and/or current foot’s surface normal.)

Any help would be appreciated!