I’m engaged on a type of character editor and I’m attempting to make a easy preview for joint rotation limits, beginning with hinge joints.
I’m having problem determining how you can decide the proper route of the min and max rotation limits.
For instance, within the Unity editor, if I’ve a joint that rotates on the X axis (1,0,0), a restrict at 0 levels is pointing alongside the native Z axis. But when the rotation axis is one thing even barely completely different like (1, 0.1, 0), the boundaries change route and I don’t know how you can calculate what angle to make use of when updating my rotation preview.
As an example what I imply, the screenshots under present Unity’s angular limits gizmo, the place the rotation axis is (1, 0, 0), and the place the axis is (1, 0.1, 0).
It looks as if there’s a cross product utilizing the rotation axis and one thing else, however I’m unsure what that “one thing else” is perhaps. Does anybody understand how that is calculated?
Right here’s principally what I’m planning to make use of for previewing the rotation limits:
Mainly only a radial stuffed picture going through the route of the rotation axis, and rotated so the fill begins on the minimal rotation restrict.
public class ArcControl : MonoBehaviour {
public Vector3 axis = Vector3.ahead;
public float minAngle;
public float maxAngle;
public Picture picture;
void Replace(){
float totalAngle = maxAngle - minAngle;
remodel.localRotation = Quaternion.LookRotation(axis, Vector3.up.Rotated(axis, minAngle));
picture.fillAmount = Mathf.Clamp01(totalAngle/360f);
}
}
public static class VectorExtensions
{
public static Vector3 Rotated(this Vector3 vector, Vector3 axis, float levels){
return Quaternion.AngleAxis(levels, axis) * vector;
}
}



