Need assistance with mesh transform

I can’t find answers thru Google like I normally do for this, so I’m here looking for someone with more experience in dynamically altering transforms. I’m creating a game with modular creatures, where you can hotswap the body, forelimbs, hindlimbs, head, etc., and I’m trying to keep the feet in their default position on the ground. The issue is, the legs vary in height, so the body Z location and pitch rotation need to adapt when the legs are swapped out. Included is a diagram of the setup with the unknown variables, and some screenshots of what I currently have setup (that obviously isn’t working). In addition, I need to figure out 3 other issues that are related, that I’m at a loss of how to solve. In list format, this is what I’m stuck on.

  1. How to set body rotation and location based on length of the legs and distance between legs
  2. How to make the feet face the surface normal angle of the ground (I have a simple function that traces straight down, but I need to adjust it based on the surface normal under each foot)
  3. How to lower each limb when the character is standing on an angle so the feet actually touch the ground (I understand that I need to adjust the relative Z location, but the solutions I’ve tried aren’t working)
  4. A way to dynamically adjust the mesh rotation to the surface normal of the ground, while maintaining the pitch from the varying leg heights

Visual aids (I’m aware some of the roll/pitch rotations are swapped, for some reason the import settings from blender didn’t take):

I think that’s everything relevant, but I’ll post more if needed

As an aside, if anyone has any interest in working on this with me, feel free to message me, I could use a good visual scripter so I can focus on the modeling.