how do I limit the angle that a bone can move using quaternions?

 0 I have an angle I want to limit for a bone of an object the user moves the bone with the mouse.Here's an examplelimit=Vector3(45,45,90);in an update loop I have:if(bone.transform.eulerAngles.x>=limit.x){bone.transform.eulerAngles.x=limit.x}Using this type of code I get flipping and vibrating of the object. If I debug.log out the values for euler angles they are also jumping around.Someone in another post suggested using modulus if(bone.transform.eulerAngles.x%360>=limit.x){bone.transform.eulerAngles.x=limit.x;} but I tried that and it still has the flipping vibrating.Does anyone have suggestions on how to limit rotations using quaternions instead of euler angles.Dan more ▼ asked Nov 27 '11 at 07:54 PM dansav 392 ● 105 ● 137 ● 158 Any chance you can use a hinge joint? That would save you time. Nov 27 '11 at 08:00 PM Peter G add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

2 answers: sort voted first
 0 A characterJoint might be easiest -- it works like a ball&socket with limits on up/down and side-side motion.Setting one Euler angle of a quat gives randomish results (see the docs.) That flipping is normal and not very fixable. In general, you have to use either Eulers or Quats as the "base" and can't go back and forth. It's a little like translating from Latin to English, changing one word, then translating back. You can get something really different.You can check the overall "cone" angle of a Quaternion, and can probably scale it down if it gets too big, but I don't know how to limit the angle to an oval instead of a ring.You could have the user control the Y and X rotation, keep them saved, and build Quaternion.EulerAngles(X,Y,0)' after each change. Or you could have the user select a point only from within a small ring in front of the bone, and use that point for a lookAt. more ▼ answered Nov 28 '11 at 05:19 AM Owen Reynolds 12.2k ● 1 ● 7 ● 46 It's a bone joint for a character so I can't apply another joint to it. I just need some method for limiting quaternions. Maybe I can turn the euler limits into a quaternion and compare quaternion to quaternion? Is that possible? Nov 28 '11 at 06:35 AM dansav A bone is simply a child. you can always add a joint -- that's what rag-dolls are. If an animation is moving it, you can still slap on another Euler-based rotation in LateUpdate.A quaternion is a direction, not a "3D oval." You could compare a quat to "forward," say, checking angle<30, but can't differentiate between the X and Z angles. Nov 30 '11 at 01:13 AM Owen Reynolds that's an interesting idea. Nov 30 '11 at 03:47 AM dansav add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users
 0 just look at the camera control mouse look and then yuo'll find how to properly use Mathf.Clamp :D more ▼ answered Nov 27 '11 at 08:33 PM anwe 114 ● 31 ● 34 ● 38 I will look up mathf.clamp I haven't heard of that. Thanks. Nov 30 '11 at 03:47 AM dansav Mathf.Clamp can be used just for removing if else statement, the problem is limiting rotation with quaternions :) Jan 19 '12 at 07:34 AM comrade add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Once you sign in you will be able to subscribe for any updates here

Topics:

x459
x300
x137
x49

asked: Nov 27 '11 at 07:54 PM

Seen: 1426 times

Last Updated: Jan 19 '12 at 07:34 AM