-1
\$\begingroup\$

I'm using Quaternion.Lerp to rotate a joint with a certain angle, but when I use the below code I find the joint rotating very far although I specified it to rotate with only 5. Any thoughts please?

Vector3 newRot.y += currentTransform.localRotation.y + 5f;
blendWeight = 0;
if ( blendWeight < 1)
{
    animationRotation = currentTransform.transform.localRotation;
    newRotation = Quaternion.Euler(newRot.x, newRot.y, newRot.z);
    blendWeight += Time.deltaTime/0.9f;
    currentTransform.transform.localRotation = Quaternion.Lerp (animationRotation,newRotation, blendWeight);
}
\$\endgroup\$
9
  • \$\begingroup\$ Only 5 what? 5 radians is a large fraction of a circle. \$\endgroup\$ Commented Aug 10, 2015 at 1:51
  • \$\begingroup\$ @SethBattin I want it 5 degrees. \$\endgroup\$
    – Tak
    Commented Aug 10, 2015 at 1:52
  • \$\begingroup\$ How are you calling your code? \$\endgroup\$ Commented Aug 10, 2015 at 2:29
  • \$\begingroup\$ It's in the lateupdate function \$\endgroup\$
    – Tak
    Commented Aug 10, 2015 at 2:30
  • 1
    \$\begingroup\$ One glaring problem here is this line: Vector3 newRot.y += currentTransform.localRotation.y + 5f; — you're forming an Euler angle vector using the y component of a Quaternion. This is unlikely to have the geometric meaning you intend. If you're trying to inherit the yaw component of localRotation, then localRotation.eulerAngles.y is closer but still fraught at certain angles because of the way Euler angles jump around near gimble lock points. It's generally safer to work in quaternions for incremental rotations, and only use Euler angles for absolute orientation. \$\endgroup\$
    – DMGregory
    Commented Nov 10, 2015 at 14:53

1 Answer 1

0
\$\begingroup\$

Try decreasing the amount of the rotation, so change 5 to a lower number like 2, if that's still a lot decrease it even more.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .