• 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
2
Question by PitchBlackCat · Mar 04, 2011 at 11:23 AM · rotationquaternionbeginner

Simple Rotation

Hey guys,

I'm new to unity and i'm already stuck on what seems to me as the simplest of functionality. I can't get the hang of rotations..

Let's say i have a Vector3(0,5,0) and i want to rotate it 30 degrees over the x-axis and 55 degrees over the y-axis, with pivot point Vector3(0,0,0).

How would one go about to achieve this? I have been wrestling with Quaternions and Transforms, but to no avail..

Any help is most welcome!

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
4
Best Answer

Answer by CHPedersen · Mar 04, 2011 at 11:41 AM

There are several ways. Quaternions, though more complicated if you dig into their math, present the simpler alternative in terms of lines of code.

With quaternions, you can instantiate a Quaternion object using one of the static methods in the Quaternion class. You mention rotations about specific axes, so we can use the AngleAxis method to create a suitable quaternion. These are then multiplied onto the vector you wish to rotate. The result is the rotated vector. So the example you described above would be:

Vector3 toBeRotated = new Vector3(0, 5, 0); Quaternion rotateVectorAboutX = Quaternion.AngleAxis(30, new Vector3(1, 0, 0)); Quaternion rotateVectorAboutY = Quaternion.AngleAxis(55, new Vector3(0, 1, 0));

 Vector3 afterRotation = rotateVectorAboutX * rotateVectorAboutY * toBeRotated;

Note that the order must always be Quaternion*Vector, never Vector*Quaternion. I'm not a math wizard, but my guess is that this is related to the dimensionality of their underlying matrix representations. When you multiply matrices, the "connecting" dimensions must match, i.e. [1x4][4x4] is okay, but not [4x1][4x4].

There are plenty other ways to go about this, like EulerAngles, if you're more into that.

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 PitchBlackCat · Mar 04, 2011 at 01:47 PM 0
Share

Thank you very much! I've been trying to get this to work for a week, searching the forums like crazy. But this is very clear example!

avatar image Matt-Downey · Aug 25, 2012 at 01:10 PM 0
Share

wow, I never knew you could multiply Quaternions by Vectors, I guess this is some of the underlying reasoning behind Quaternions being called Euler parameters?

[edit:] and infinite respect btw to this answer.

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

1 Person is following this question.

avatar image

Related Questions

Quaternion and rotation of object 1 Answer

2D character rotation wrong direction when moving 1 Answer

Quaternion - Rotate / Unrotate Error 0 Answers

simple movement and rotate help! 1 Answer

i have rotated an gameobject but the axis of the object did not change 2 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