Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Joel_Shaji · Dec 02, 2020 at 12:26 PM · rotationlocalrotationoperatorquaternion.slerp

Quaternion slerp loop exits before equality of quaternions

The loop involves 3 transforms: playerBody, playerHTP and playerVTP which is a child object of playerHTP. I want all 3 of them to have the same rotation which is the rotation that playerBody has. So I created a while loop that slerps playerHTP to playerBody, and simultaneously slerps playerVTP to a local rotation of Quaternion.Euler(0,0,0). It works sometimes but other times it does not work which is why I cannot understand what is going wrong? I guess it has something to do with different cases of playerBody's rotation but I dont understand why different rotations of playerBody are reacting differently. Here is my code:

         while (playerHTP.transform.rotation != playerBody.transform.rotation && playerVTP.transform.localRotation != Quaternion.Euler(0, 0, 0))
         {
             if (playerHTP.transform.rotation != playerBody.transform.rotation)
                 playerHTP.transform.rotation = Quaternion.Slerp(playerHTP.transform.rotation, playerBody.transform.rotation, 5 * Time.deltaTime);
             Debug.Log("HTP rotation: " + playerHTP.transform.rotation + " player rotation: " + playerBody.transform.rotation);
             if (playerVTP.transform.localRotation != Quaternion.Euler(0, 0, 0))
                 playerVTP.transform.localRotation = Quaternion.Slerp(playerVTP.transform.localRotation, Quaternion.Euler(0, 0, 0), 5 * Time.deltaTime);
             Debug.Log("VTP rotation: " + playerVTP.transform.localRotation);
             yield return null;
         }

EDIT: I tried this code and it gave more accurate results but still the same issue happens sometimes:

 float time = 0f;
         Quaternion initPlayerRot = playerBody.transform.rotation;
         Quaternion initPlayerHTPRot = playerHTP.transform.rotation;
         Quaternion initPlayerVTPRot = playerVTP.transform.localRotation;
         while (playerHTP.transform.rotation != playerBody.transform.rotation && playerVTP.transform.localRotation != Quaternion.Euler(0, 0, 0))
         {
             playerHTP.transform.rotation = Quaternion.Slerp(initPlayerHTPRot,initPlayerRot,time);
             playerVTP.transform.localRotation = Quaternion.Slerp(initPlayerVTPRot,Quaternion.Euler(0, 0, 0),time);
             time += 5*Time.deltaTime;
             yield return null;
         }


The issue only occurs sometimes that is why I believe it is something to do with specific values of quaternion rotations. If it was some other part of my code causing it, it would happen everytime.

I also confirmed this with the Debug.Log() that you see. I added the ones in the code and a final one after the loop was over to notify me that the loop has exited. As I expected, when the rotations happened correctly, the loop exited after equal quaternion values being printed (equal for playerBody and playerHTP, and (0,0,0,1) for playerVTP as it was local rotation) , and when wrong rotations happened, the output values were unequal.

This loop is executed when my player enters a trigger and it can enter it at any angle it wants which is why the Quaternions vary based on the current play through. That is the only possible reason I can think of why this happens only sometimes

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by xxmariofer · Dec 02, 2020 at 12:53 PM

the first code is simply wrong, the second looks fine to me, are you sure it is not working? can you change the while statement

  while (playerHTP.transform.rotation != playerBody.transform.rotation && playerVTP.transform.localRotation != Quaternion.Euler(0, 0, 0))

to

 do
 {
 } while(timer < 1);
Comment
Add comment · 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

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

189 People are following this question.

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

Related Questions

Using Quaternion.Slerp() to rotate an NPC. 1 Answer

Use curve effect on rotation? 1 Answer

Clamped rotation of turret problem 0 Answers

how to rotate bullet towards target direction?unity2D 0 Answers

Quaternion lerp is not rotating my object to the desired rotation? 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