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
1
Question by Patyrn · Apr 06, 2011 at 02:16 AM · vector3quaternion

Rotate a vector

I have a vector that I want to rotate so it points up at a 45 degree angle from its original direction. When I say "up" I mean so it is still traveling in the same direction except for on the y axis.

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 Joshua · Apr 06, 2011 at 03:23 AM 0
Share

What is the question? How to do this trough code? How to do this in the editor? Please just read http://unity3d.com/support/documentation/$$anonymous$$anual/Unity%20Basics.html and save your self a LOT of questions.

2 Replies

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

Answer by Bunny83 · Apr 06, 2011 at 03:25 AM

http://answers.unity3d.com/questions/40582/rotate-a-vector3-direction


edit
To rotate around the local right vector you can calculate it like this:

{ // the Vector3 you want to rotate var myVector : Vector3;

 // help vector that points to the right
 var right : Vector3 = Vector3.Cross(myVector,Vector3.up);

 // rotate myVector around right
 myVector = Quaternion.AngleAxis(45, right) * myVector;

[...]

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 Patyrn · Apr 06, 2011 at 03:37 AM 0
Share

I know how to rotate it about a world axis, or an axis obtained from a transform, but what about rotating it around its own "right" if it is considered to be "forward"

avatar image Bunny83 · Apr 06, 2011 at 11:49 AM 0
Share

Do you mean that you don't have the corresponding transform available, but only the Vector3 that points "forward"? If this Vector3 lies in the x-z-plane (more precise it don't face straight up) you can calculate the "right" vector via cross-product. I can add an example

avatar image Patyrn · Apr 06, 2011 at 05:31 PM 0
Share

Cool this looks like exactly what I needed, thanks.

avatar image
0

Answer by groovecode · Apr 06, 2011 at 04:49 AM

Maybe not the best way, and maybe it doesn't even work (can't try it out right now, rebuilding my pc). But I'd try something like:

Quaternion offset = Quaternion.Inverse(Quaternion.FromToRotation(myVec, Vector3.forward));
Quaternion rotateUp = Quaternion.FromToRotation(Vector3.forward, Vector3.forward + Vector3.up);
myVec = (offset * rotateUp) * myVec;

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

No one has followed this question yet.

Related Questions

c# modify only one axis of a quaternion 2 Answers

Unity's equivalent of Vector3.Transform(...) 2 Answers

How Make an Vector Follow an Quaternion? 1 Answer

Help with Quaternions and Vector3s 2 Answers

Get rotation from a vector direction. 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