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 EricIAmEric · May 23, 2012 at 06:59 PM · animationquaternionproceduralslerpbone

How to detect end of slerp when moving bone

I am trying to animate a bone procedurally when it is right-clicked. The code animates the bone to its lower position, then back to its upper (original) position. But the test to determine whether it has reached the upper position doesn't work. The calculated angle between the bone's position and the target goes to zero when the bones is driven down to the lower position, but when it is driven back up it never goes below about 25 degrees.

I have also tried testing for equality between the bone position and target (i.e. if (target == myAbsoluteBoneRotation) ...) but with similar results: the down test works, the up test doesn't, even though the reported values are identical. (Perhaps there is a precision issue here though.)

Any idea what is going on? All suggestions most gratefully received...

 public class BoneController : MonoBehaviour {
     
     // get the transform of the bone
     public Transform _bone;
     
     // store absolute rotation
     private Quaternion myAbsoluteBoneRotation;
     
     // hold rotations
     private Quaternion myBoneRotation;
     
     // control animation sequence
     private bool animatingBone = false;
     private bool animationDirectionUp = false;
     private const float animationSpeed = 5.0f;
     
     // targets
     private Quaternion target;
     private Quaternion upTarget;
     private Quaternion downTarget;
     
     
     void Start () {
         
         // the two positions of the bone
         upTarget = new Quaternion(-0.2f, 0.3f, 0.0f, -0.9f);
         downTarget = new Quaternion(-0.2f, -0.2f, -0.1f, -1.0f);
         
         // initialise to bone's position
         myAbsoluteBoneRotation = _bone.rotation;
     }
     
     
     
     void LateUpdate() {
         
         // if the right mouse button is down, move the bone
         if (Input.GetMouseButtonDown(1)) {
             animatingBone = true;
             animationDirectionUp = false;
             target = downTarget;
         }
         
         
         if (animatingBone) {
         
             // find angle between actual position and target
             float angle = Mathf.Abs(Quaternion.Angle(myAbsoluteBoneRotation, target));
             
             if (animationDirectionUp) {
                 // check whether upper limit reached
                 if (angle > 0.0f) {
                     myAbsoluteBoneRotation = Quaternion.Slerp(myAbsoluteBoneRotation, 
                         target, animationSpeed * Time.deltaTime);
                 } else {
                     // we have reached upper limit, so halt animation
                     animatingBone = false;
                 }
                 
             } else {
                 // check whether lower limit reached
                 if (angle > 0.0f) {
                     myAbsoluteBoneRotation = Quaternion.Slerp(myAbsoluteBoneRotation, 
                         target, animationSpeed * Time.deltaTime);
                 } else {
                     // we have reached lower position, so start animation to upper position
                     animationDirectionUp = true;
                     target = upTarget;
                 }
             }
             
             // move the bone
             _bone.rotation = myAbsoluteBoneRotation;
             
         }
     }    
 }
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 EricIAmEric · May 24, 2012 at 11:30 AM 0
Share

The best solution I have found so far is to time limit the up animation. So, in pseudo code:

when start up animation, reset timer

apply up animation while timer < some value

This is awful. Does anyone have a better solution?

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Slerp with rotations from different spaces 0 Answers

Unity animator with blender bones causes gimbal lock. 1 Answer

Rotating Armature During Animation 1 Answer

Mouse Over Wont Work on Bone Animated Meshes. 1 Answer

Quaternion.Slerp 1 Answer


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