I have a ragdoll type setup. I want the arm of the ragdoll (long rigidbody) to point at a transform.position (in world space). On the arm is a configurable joint. The connected body of the configurable joint is the body (rigidbody).
I guess I need to find the local rotation the arm needs to have to point at the transform.position and then translate that in the joint space. But my code does not produce the wanted functionality (not even close)
Can someone help me out?
` public void RotateTowardsPoint(Rigidbody body1, ConfigurableJoint joint, Vector3 pointAtDistance) { Vector3 directionToTarget = pointAtDistance - anchor.transform.position;
Quaternion targetRotation = Quaternion.LookRotation(directionToTarget);
Quaternion localRotation = Quaternion.Inverse(body1.transform.parent.rotation) * targetRotation;
joint.targetRotation = localRotation ;
}`
Called this function in FixedUpdate