-1

Im currently working on procedural animation trying to understand the fundamentals and how to implement it better. I am stuck trying to work out how to rotate the body of this Quadruped based on its legs. I understand I would have to get the distance between the legs but I dont understand how I can translate that into Quaternion/Rotation values and apply it to the body it the centre!

Any advice or help would be appreciated! Thankyou!

enter image description here

Ruzihm
  • 19,749
  • 5
  • 36
  • 48

1 Answers1

0

First, I would use your calculations to determine the desired position of the front hips and the left rear hip. Then, I would use some vector math and Quaternion.LookRotation to solve for the rotation:

Quaternion GetBodyRotation(Vector3 frontLeftLegWorldPosition, 
        Vector3 frontRightLegWorldPosition, 
        Vector3 rearLeftLegWorldPosition)
{
    Vector3 localForward = frontLeftLegWorldPosition - rearLeftLegWorldPosition;
    Vector3 localRight = frontRightLegWorldPosition - frontLeftLegWorldPosition;
    Vector3 localUp = Vector3.Cross(localForward, localRight);
    
    return Quaternion.LookRotation(localForward, localUp);
}

Then, I would apply that rotation to the body with bodyTransform.rotation = resultOfAboveMethod;.

Then, assuming the left rear hip and front right hip are rotationally symmetrically positioned, you can set the position of the body such that it is in between the front right hip and left rear hip with bodyTransform.position = 0.5f * (frontRightLegWorldPosition + rearLeftLegWorldPosition);

Ruzihm
  • 19,749
  • 5
  • 36
  • 48