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 TheEndcaster · Jul 21, 2018 at 02:41 AM · vector3quaternion

Quaternion to Vector3,Player transform in vector3?

Hi, i am an absolute beginner at unity and was wondering: If you get the rotation of a GameObject by using GameObject.transform.rotation it comes out as a Quaternion. Is there any way to change that into a Vector3? ,Hi, i'm an absolute beginner at unity, and i was wondering

If you have a GameObject and you get it's rotation using player.transform.rotation, it comes out as a Quaternion.

Is there anyway to change that into a Vector3?

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 JVene · Jul 21, 2018 at 03:09 AM

@TheEndcaster, one must ask what you might expect from a Vector3? There is a conditional answer to your question.

If what you want is the angle of rotation for this Quaternion on the x, y and z axis, you can use the eulerAngles property. It returns a Vector3 of those 3 angles in degrees.

That basically contains what you see in the inspector when it shows the rotation of an object.

Since you are a beginner, let me extend the answer with a few points about concepts your question hints but doesn't ask.

When you say "comes out as a Quaternion", that is because the type of the rotation member of the transform is a Quaternion.

When you "get the rotation", you're reading the property.

Properties are a kind of intelligent version of member variables. The can take specific actions, written in code, when you read or write to them. This is what happens when you use:

 Vector3 angles = player.transform.rotation.eulerAngles;

In this code, a Vector3 is assigned a copy of a Vector3 created in the "get" operation of the property "eulerAngles", which at that moment is calculated form the internals of the Quaternion for you. Even though there is no function call operator ( the () that would follow the name of a function when a function is called ), the "get" operation of the property implies a function is being called.

Unity uses Vector3 for several 3 parameter needs, not all of which are actually vectors. A vector implies a direction and a distance. It looks like a point, but the implication is that it is a point relative to the origin. However, when you read the eulerAngles property (and in other contexts), Unity must return an object with 3 float values, so they use the Vector3 - but there is no resemblance to an actual vector in what it returns, and can't be used as a vector in other contexts.

Also, GameObject, spelled with a leading capital, is a type. A type, to C#, specifies the kind of data. It can be used to declare new values (like the Vector3 line I posted above), or it can be used to gain access to static member functions and variables. When you typed "GameObject.transform.rotation", we all know what you mean, but I wanted to point out that this is not a valid statement in C# because there is no static member "transform" in the GameObject class.

In Unity there is a member of several components and classes called gameObject, spelled with a lower case g. This is an instance. It is the formed, working object of the type GameObject, and it does have a transform member.

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

109 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

Related Questions

Perpendicular Vector3 0 Answers

How to use Quaternion to rotate an object in only one axis? 1 Answer

Planetoid Gravity 1 Answer

How is the rotation of a Transform converted into a Vector3 in the inspector ? 2 Answers

Can someone explain this part of the PlayerMoveController.js script in the AngryBots demo? 3 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