Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Griffo · Apr 29, 2016 at 07:38 AM · rotationrotaterotate objectrotatearound

Quaternion, eulerAngles, localEulerAngles Driving me mad

Hi,

I have a reload animation that i want to Slerp slightly, I've tried using Quaternion because I thought it alway taken the shortest route?

I have 2 Quaternion, 1 (3,964, -176.115, 0, 0) and (0,-176.115, 0, 0) but when using Slerp it goes the long way around.

I've tried eulerAngles and localEulerAngles and seem to get the same results.

Here is a snippet of my code.

Any help would be greatly appreciated ..

 var _reloadRotation : Quaternion;
 private var _transformsRotation : Quaternion;
 
 private var j : float;
 
 function reloadLerpPosition ()
 {
     _transformsRotation = transform.rotation;
 
     j = 0;
     while(j < 1)
     {
         j += Time.deltaTime/0.6;
         j = Mathf.Clamp(j, 0, 1);
             transform.rotation = Quaternion.Slerp(_transformsRotation, _reloadRotation, j);
         yield;
     }
 }
 
Comment
Add comment · Show 6
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 Scribe · Apr 29, 2016 at 10:04 AM 0
Share

Slerp works fine, what most worries me is where you say you have two quaternion '(3,964, -176.115, 0, 0) and (0,-176.115, 0, 0)', the components of a quaternion should be clamped between -1 and 1 I believe. are you setting the x,y,z components of the quaternion yourself somewhere? it is quite likely that (1, -1, 0, 0) lerping to (0, -1, 0, 0) will go quite a distance.

avatar image Griffo Scribe · Apr 29, 2016 at 10:18 AM 0
Share

@Scribe Hi, the (3,964, -176.115, 0, 0) is the position of the animated arms and weapon, that never changes because it's child of another Transform, and (0,-176.115, 0, 0) is the target rotation I'm trying to achieve ..

avatar image Scribe Griffo · Apr 29, 2016 at 11:07 AM 0
Share

So you are happy that you are rotating towards an EULERIAN angle of (0, 180, 0), which is the equivalent to a QUATERNION of (0,-176.115, 0, 0). On top of this, the objects are at the 5 dimensional position (3,964, -176.115, 0, 0)?

Show more comments
avatar image meat5000 ♦ · Apr 29, 2016 at 10:56 AM 0
Share

Here's a good little post

http://answers.unity3d.com/answers/149873/view.html

avatar image Griffo meat5000 ♦ · Apr 29, 2016 at 11:19 AM 0
Share

O$$anonymous$$G !!!!!!

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Outliver · Apr 29, 2016 at 08:32 AM

That's because rotation is presented in Quaternions which cannot be converted into euler angles with 100% precision. The problem occurs when you cross the 0 point on the x axis (afair). Try using Rotate() or RotateAround(). It's generally a good advice to avoid manipulating Quaternions directly. If that doesn't work: where, how and by what is your method being called?

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 Griffo · Apr 29, 2016 at 09:53 AM 0
Share

@Outliver Thanks for the input,

First it's being called in what I call the AnimationCtrlWeapon script, when the player runs out of ammo a reload function is called, then in that I first call the reloadLerpPosition function and when thats finished it calls the reload animation.

I've also tried ..

     var reloadRotation : Vector3;
     
     private var localRotationX : float;
     private var localRotationY : float;
     private var localRotationZ : float;
     
     function reloadLerpPosition ()
     {
         localRotationX = transform.localEulerAngles.x;
         localRotationY = transform.localEulerAngles.y;
         localRotationZ = transform.localEulerAngles.z;
     
         j = 0;
         while(j < 1)
         {
             j += Time.deltaTime/0.6;
             j = $$anonymous$$athf.Clamp(j, 0, 1);
     
             transform.localEulerAngles.x = $$anonymous$$athf.Lerp(localRotationX, reloadRotation.x, j);
             transform.localEulerAngles.y = $$anonymous$$athf.Lerp(localRotationY, reloadRotation.y, j);
             transform.localEulerAngles.z = $$anonymous$$athf.Lerp(localRotationZ, reloadRotation.z, j);
             yield;
         }
     }

And I still can't get it right :(

avatar image Outliver Griffo · Apr 29, 2016 at 11:04 AM 0
Share

First of all, I'm still not quite sure what you're trying to achieve exactly. Do you really want to lerp in every direction? Why "while (j < 1)" if you $$anonymous$$athf.Clamp() anyway? That's an infinite loop. And why is your reloadRotation a Vector3, not a Quaternion?

Again: do not set quaternions or euler angles manually. Have you tried something like this already? transform.Rotate( reloadRotation * j ); (untested pseudo code)

If that doesn't work, maybe you'll need to make sure, the rotation is never more than 180° away. Like so:

reloadRotation.x = reloadRotation.x > 180 ? reloadRotation.x - 360 : reloadRotation.x;

...and so on (again, just pseudo-code).

avatar image Griffo · Apr 29, 2016 at 10:04 AM 0
Share

I thought this would be simple, just to Slerp from (3,964, -176.115, 0, 0) to (0,-176.115, 0, 0)

Or Lerp from (3,964, -176.115, 0) to (0,-176.115, 0) in the shortest distance ..

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

53 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

Related Questions

How to rotate an object according to the camera's view? 1 Answer

rotate object around another object 1:1 1 Answer

Rotate object in the direction where it is going 1 Answer

Have an object continuously rotate towards another 1 Answer

[2D] Tranform.RotateAround flickers arrow between two positions when the mouse is close to the player 0 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