Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by dansav · Nov 27, 2011 at 07:54 PM · quaternionanglelimiteuler

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

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 example
limit=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

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Peter G · Nov 27, 2011 at 08:00 PM 0
Share

Any chance you can use a hinge joint? That would save you time.

2 Replies

· Add your reply
  • Sort: 
avatar image
-1

Answer by anwe · Nov 27, 2011 at 08:33 PM

just look at the camera control mouse look and then yuo'll find how to properly use Mathf.Clamp :D

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image dansav · Nov 30, 2011 at 03:47 AM 0
Share

I will look up mathf.clamp I haven't heard of that. Thanks.

avatar image comrade · Jan 19, 2012 at 07:34 AM 0
Share

$$anonymous$$athf.Clamp can be used just for removing if else statement, the problem is limiting rotation with quaternions :)

avatar image
0

Answer by Owen-Reynolds · Nov 28, 2011 at 05:19 AM

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.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image dansav · Nov 28, 2011 at 06:35 AM 0
Share

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. $$anonymous$$aybe I can turn the euler limits into a quaternion and compare quaternion to quaternion? Is that possible?

avatar image Owen-Reynolds · Nov 30, 2011 at 01:13 AM 0
Share

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.

avatar image dansav · Nov 30, 2011 at 03:47 AM 0
Share

that's an interesting idea.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Problem with Quaternion.Euler() when rotating object 3 Answers

How to raycast using a vector3 and a rotation? 1 Answer

How can I multiply the rotation of a mirrored object? 1 Answer

Object makes random jumps in rotation 1 Answer

Raycasting at an offset angle? 4 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges