Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
8
Question by chillypacman · May 12, 2012 at 09:09 AM · rotationquaternionvector

Rotation to direction vector?

How can I get a normalized direction vector from an objects rotation?

Comment
Add comment · Show 1
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 Rodolfo-Rubens · Feb 14, 2015 at 04:10 AM 0
Share

How can I do this without using a transform component? Like, using a Quaternion or a Vector3 itself?

3 Replies

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

Answer by aldonaletto · May 12, 2012 at 09:17 AM

As @jimmyjjeeter suggested, you can use transform.forward (as well as transform.up for the up direction, transform.right for right, -transform.right for left etc.).
If you have a quaternion but not the transform, you can rotate a vector like this:

   var rotatedVector = someQuaternion * Vector3.forward;

NOTE: Order matters in the quaternion world: it must always be quaternion x vector (vector x quaternion produces an error).

Comment
Add comment · Show 1 · 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 duke · Mar 28, 2013 at 04:10 AM 0
Share

Thanks for answering with the math behind the function @aldonaletto

avatar image
11

Answer by JimmyJJeeter · May 12, 2012 at 09:10 AM

Isn't that just transform.forward?

Comment
Add comment · Show 1 · 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 chillypacman · May 12, 2012 at 09:14 AM 1
Share

@JimmyJJeeter ugh yes, you are right, can't believe I forgot about that.

avatar image
8

Answer by Nition · Aug 09, 2017 at 12:45 AM

I always end up here when I've forgotten how to convert a rotation to a direction vector, so here's a complete answer for anyone else ending up here or for me 6 months from now.

For a Quaternion rotation:

 Vector3 forwardVector = yourQuaternionRotation * Vector3.forward

And for a Vector3 rotation:

 Vector3 forwardVector = Quaternion.Euler(yourVector3Rotation) * Vector3.forward


Comment
Add comment · Show 5 · 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 Nition · Feb 23, 2018 at 03:13 AM 5
Share

lol, just came looking for how to do this again. I see it's been just over six months...

avatar image Nition Nition · Aug 15, 2018 at 02:43 AM 2
Share

Can't believe I'm here again almost right on another six months. I'm going to write this info down locally now so this may be my last visit.

avatar image RShields Nition · Aug 15, 2018 at 02:48 AM 0
Share

I generally find that it's easier for me to remember something if I really understand why it works. I'd recommend doing that here. $$anonymous$$eywords are "rotation matrix" and "transformation matrix" (and, of course, "quaternion")

Show more comments
avatar image LohnS · Oct 22, 2018 at 03:03 PM 0
Share

Very helpful, thank you :) I totally get how you need to re-remember things sometimes. Fantastic you did this haha

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

12 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

Related Questions

Object not rotating when the associated trigger is triggered 1 Answer

Clamping or testing an angle between objects. 1 Answer

Gradual Rotation of Character from 2 Axis Input Sources 0 Answers

Efficiency of transform.forward, up, and right 2 Answers

Rotating a direction Vector3 by Quaternion 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