• 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
1
Question by kakulukiya · Oct 23, 2014 at 12:17 AM · euleranglesscaling

Scaling a Rotation Difference

I have the difference between 2 rotations - start and current rotation of an object as a Quaternion. I want to apply this difference in rotation to a new object. But I also want to scale this difference along X, Y and Z axis. I tried converting to Euler Angles and multiplying individual angles and then converting back to Quaternion like

Quaternion rotDiff; // difference between start and end rotaions

Vector3 eulerRotDiff = rotDiff.eulerAngles;

Vector3 scaledEulerRotDiff = new Vector3(eulerRotDiff.x xScale, eulerRotDiff.y, eulerRotDiff.z zScale);

Quaternion scaledRotDiff = Quaternion.Euler(scaledEulerRotDiff);

// Applying scaled rotation

target.transform.rotation = targetStartRot * Quaternion.Euler(-scaledRotDiff.x, scaledRotDiff.z, 0);

But sometimes, this causes a 180 degree snap. If I apply the rotation without scaling, it works. How can I scale the rotation properly ?

Comment
Add comment · Show 7
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 robertbu · Oct 23, 2014 at 04:10 AM 0
Share

You can scale the rotation uniformly using Quaternion.Slerp(). I would expect problems going to and back from eulerAngles. Their representation changes. For example you can set a rotation of (180,0,0), and read back (0,180,180). Depending on what you are doing, you may be able to separate out your rotation into three rotations along three axes and manage each separately, but I'd have to fully understand the problem you are trying to solve to figure out how to set this up.

avatar image kakulukiya · Oct 23, 2014 at 04:24 AM 0
Share

How would I use quaternion.slerp ? Set t to > 1 ? Like 1.5 to scale rotation 1.5 times along all axes ?

I am trying to use gyroscope data to rotate a gameobject. When the gyroscope rotates a little, I want my gameobject to rotate to a large extent. If the gyroscope isn't rotated, gameobject shouldn't be rotated either. Do you need any more details ?

avatar image robertbu · Oct 23, 2014 at 04:40 AM 0
Share

Hummm. Slerp() will not work for this. Untested, but try this:

 float angle;
 Vector3 axis;
 rotDiff.ToAngleAxis(out angle, out axis);
 Quaternion scaledRotDiff = Quaternion.AngleAxis(angle * 1.5f, axis);
avatar image kakulukiya · Oct 23, 2014 at 04:56 AM 0
Share

I tried AngleAxis before. It caused 90 degree snaps. Probably because it will scale all 3 angles. I am not sure though. I just want to scale Y and X axis.

avatar image robertbu · Oct 23, 2014 at 06:43 AM 0
Share

The problem is that going from one rotation to another can be represented in multiple ways. In my extreme example, these two rotations (180,0,0) and (0,180,180) are the same. You can see that how much of a rotation is due to 'z' is dependent on the representation you selected. And ignoring the 'z' would produce very different rotations depending on which of these two representations you used.

Using a frame of reference, you might be able to pull your rotation apart into three consistent rotations and then put them back together again, but it will be more difficult that just reading eulerAngles. You might try the code I gave for this answer:

http://answers.unity3d.com/questions/696271/how-create-modern-aircrafts-hud.html

The code at that answer pulls a rotated object into heading, pitch and roll. If you use this code, you likely will need experiment on the order you put them back together to build the new rotation.

Show more comments

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Detect touch location? 1 Answer

How to handler rotation of a Gameobject while aligning it with normals 1 Answer

Alternative to Quaternion.LookRotation() ? 2 Answers

Holding 2 buttons down for movement. 1 Answer

rotate slowly! 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