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 elnurv47 · Oct 16, 2020 at 03:32 PM · rotationtransformvector3euleranglesunityengine.object

Euler Angles and Vectors

Hi, I am learning how to make a third-person game and I noticed that Euler Angles uses vectors in order to rotate objects. (Look at the marked area in the screenshot, mine is almost the same as that.) I am having trouble to understand how vectors can be used to represent the rotation of the object. Thank you in advance. alt text

unity.png (54.0 kB)
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

3 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by unity_ek98vnTRplGj8Q · Oct 16, 2020 at 04:39 PM

Any rotation can be represented by a sum of rotations about the 3 main axis (X, Y, and Z axis). For example if I wanted to represent a rotation about the y axis in the positive direction, or in other words a rotation to the right, I could use the vector (0, y, 0) where y represents how large of an angle in degrees I want to rotate. Similarly if I want to tilt forward or backward I could rotate about the x axis. A rotation of (0, 0, 0) represents an object that is aligned with the 3 axis ("forward" for the object is along the world Z axis, "up" for the object is along the world Y axis, and "right" for the object is along the world X axis). Therefore, the orientation of any object can be represented as an offset in degrees along some combination of the 3 axis, relative to this default orientation. So if I wanted to represent a more complex rotation, I could simply find which combination of basic axial rotations add up to represent the overall rotation.


It is worth noting that given any orientation there are multiple sets of Vector3's (what we call Euler Angles) that represent that orientation. For example, the default orientation can be represented by (0, 0, 0) OR (0, 360, 0) OR (360, 360, 360) etc.


Also worth noting is that it matters in what order you apply each axial rotation. When you give Unity a rotation of (10, 20, 30) it will first take the rotation about the X axis, then apply the rotation about the Y axis, then apply the rotation about the Z axis. Other programs may not use this convention. To see why the order matters, imagine a rotation of (90, 90, 0). Rotating about the X axis then the Y axis (IMPORTANT: this is the new local Y axis after applying the rotation, NOT the world Y axis) will give a different rotation than first rotating on the Y axis, then rotating on the X axis. Edit: The order is actually Z, then X, Then Y

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 unity_ek98vnTRplGj8Q · Oct 16, 2020 at 04:48 PM 0
Share

I would also like to mention that using Vector3's (Euler Angles) to represent a rotation is great for small rotations or rotations about 1 or 2 axis, mostly because they are intuitive and easy for a person to look at and grasp the orientation of the object. There are several complications that using Euler Angles can cause for more complex rotations (gimbal lock), so Unity and every other 3D graphics program out there uses Quaternions to actually represent the object's rotation. Quaternion's are a more complicated but much more robust way of representing rotations. While you can use Euler Angles to manipulate rotations in Unity, Unity always first converts those Euler Angles to a Quaternion before doing anything with them. It is also super useful to learn how to use the Quaternion class in Unity. You don't need to know what a Quaternion is or how it works, but the helper functions in the Quaternion class are enough to do any rotational manipulation you want.

avatar image Bunny83 · Oct 16, 2020 at 04:58 PM 0
Share

Unity's euler angles order is Y-X-Z or Z-X-Y depending if you think about local or worldspace rotations. So when you think of a non rotated object as a basis, the rotation represents Y degrees around the objects local y axis, followed by X degree on the local (now rotated) x axis, followed by Z degrees around the (now rotated) z axis.


Another way to view it is Z degrees around the global z axis, followed by X degrees around the global x axis followed by Y degrees around the global Y axis.


You said the order is X-Y-Z which is not true, see the documenation for reference.

In Unity these rotations are performed around the Z axis, the X axis, and the Y axis, in that order.

avatar image unity_ek98vnTRplGj8Q Bunny83 · Oct 16, 2020 at 05:05 PM 0
Share

Thank you for the correction, I will edit my answer

avatar image
0

Answer by elnurv47 · Oct 16, 2020 at 05:21 PM

Thanks for your reply. I still can't get this topic. Let's say we have a script like this: alt text

As we know it makes the character move forward 1 unity if we press "W". Right ? The thing that I don't get is that how those x, y, z are converted when we write something like this:

target.eulerAngles = new Vector3(0, 90, 0);


basicscript.png (12.4 kB)
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 unity_ek98vnTRplGj8Q · Oct 16, 2020 at 10:21 PM 0
Share

Vector3's are just a data structure that contain 3 numbers, so you can use them to represent a lot of different things.


You can use them to represent an objects position: transform.position is a Vector3 that represents how far an object is from the world origin along each world axis.


You can use them to represent direction. Vector3.forward represents the World Z axis, which is the default forward direction. Vector3.forward is always the same, and it is (0, 0, 1). You can also have direction vectors that change based off of an objects orientation. For example, transform.forward represents the forward direction of the object, relative to world axis. This is not the same as the rotation, but it IS changed by rotation. For example the transform.forward of an object that has the default rotation is (0, 0, 1), or in other words the objects local forward direction matches up with the Global forward direction. If an object if facing backwards, its forward vector is (0, 0, -1). If an object is facing to the right it is (1, 0, 0) etc. Vector3.forward is a pure direction meaning that it has a length of 1.


If you want to move an object in a direction you can add a direction vector to its position vector, like in your code above. That's all that is happening, there are no Euler Angles in your code above. You are just seeing different applications of a collection of 3 numbers. You will get into trouble if you try to use Vectors that represent direction as a rotation Vector, or if you use a rotation vector as a position vector (unless you really really know what you are doing).


TLDR: There is no relation between the Vector3 in your code snippet and in the Vector3 used to set the Euler Angles in a rotation. They are separate use cases for the Vector3 data structure.

avatar image elnurv47 unity_ek98vnTRplGj8Q · Oct 17, 2020 at 09:56 AM 0
Share

Thank you very much, you helped me a lot.

avatar image
0

Answer by eliteforcevn · Apr 09, 2021 at 03:18 AM

to convert to true vector degree in the inspector use

     if(transform.localEulerAngles.x != lastXDegree)
     {
         lastXDegree = transform.localEulerAngles.x;

         Debug.Log("transform.localEulerAngles.x = " + transform.localEulerAngles.x);

         float xDegree = ((lastXDegree + 540) % 360) - 180;

         Debug.Log("Convert X Degree = " + xDegree);

         Debug.Log("Sin X = " + Mathf.Sin(xDegree));
         Debug.Log("Cos X = " + Mathf.Cos(xDegree));
     }
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

233 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 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

c# modify only one axis of a quaternion 2 Answers

Object wont rotate in the opposite direction 1 Answer

Using xbox controller with top down shooter 0 Answers

Worldspace EulerAngle.x regardless of z rotation ? 3 Answers

Rotation drift with transform.eulerAngles 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