After I attach a (hand) rigidbody to another rigidbody with a FixedJoint, how can I use AddForce() to move the whole thing to a target location, and have it stop on the target?
When not attached, I use the following to move an RB to a target:
Vector3 dist = MoveToTarget.transform.position - Hand.transform.position;
// calc a target vel proportional to distance (clamped to maxVel)
Vector3 tgtVel = Vector3.ClampMagnitude(toVel * dist, maxVel);
// calculate the velocity error
Vector3 error = tgtVel - HandRb.velocity;
// calc a force proportional to the error (clamped to maxForce)
Vector3 force = Vector3.ClampMagnitude(gain * error, maxForce);
HandRb.AddForce(force);
PlayerRb.AddForceAtPosition(-1*force, transform.position);
This works quite well, for very specific values of toVel, gain, and mass.
However, as soon as I attach the hand to something else, the algorithm above produces highly erratic motion. I think I can control it somewhat better if I tweak the toVel, maxForce and gain to suit, but I need to calculate this mathematically, not through trial and error.
Does the ratio of mass between hand and attached object matter? Is there a better algorithm which I can use which is not so sensitive to the involved masses?