Having success with your generous help involving the smooth translation between position vectors, I tried to apply the same technique to the bound game object’s direction vector, which is stored in Unity as a quaternion.
// inside my interpolation routine, assume values to // be filled with pertinent data
var tLerpVal = i * tStepSize;
storage = Vector3.Lerp(aFromPos, aToPos, tLerpVal);
transform.localRotation.x = storage.x;
transform.localRotation.y = storage.y;
transform.localRotation.z = storage.z;
but all I can accomplish with this is to reorient the rotation vector of the bound transform to <0,0,0>
I’m having a hard time searching the forum for a means of interpolating direction smoothly.
Thank you in advance for any shared insights.
Are you saying that you want to interpolate the localRotation as well as the position? If so then look at using Quaternion.Slerp using the same techniques as Vector3.Lerp.
Aha. Thanks for the nudge!
Ok, so the algorithmic aspects of the Interpolate Direction Vectors are functional, but producing undesirable results. What I have is servicable if I want to groove a given orientation to another transform, because I know the scalar W value of that Quaternion…
but what about an arbitrary Direction Vector? How do I determine the normalized W component of this arbitrary rotation to populate the target orientation?
(i.e. filling the X,Y,Z fields of the rotation and keeping W at 0 does not render the XYZ components of the desired arbitrary orientation to be correct.)
I don’t think you should ever really be setting the x, y and z components directly. Instead I’d use transforms that then get interpolated directly or that use the helper functions (LookAt, Quaternion.LookRotation) to get rotated or quaternion set.
Nice! What I’m doing that I think works is read in an arbitrary direction vector and then use Quaternion.Euler() to return a quaternion based upon that direction.
Now this works with my position interpolation:
if(relative)
end_Position = start_Position + end_Position;
… and then Vector3.Lerp()
but in the direction interpolation routine if I do:
start_Direction = transform.localRotation;
if(relative)
{
end_Direction.x = start_Direction.x + end_Direction.x;
end_Direction.y = start_Direction.y + end_Direction.y;
end_Direction.z = start_Direction.z + end_Direction.z;
}
end_Direction1 = Quaternion.Euler(end_Direction);
then use Quaternion.Slerp()
…this example doesn’t reorient the rotation of the transform to a new “relative” position… and I’m not sure why. Any insights?
I guess what I need is either to get inside the Euler member function of the Quaternion class and reverse engineer it or find a comparable function that can do the opposite of:
rotation = Quaternion.Euler(3d_Direction_Vector);