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 rich_seabirdsim · Feb 02, 2014 at 08:44 PM · quaternionrotatevector

How to rotate a vector

I'm writing a simple control function for my airplane-like object with airplane-like controls. I'd like to use my velocity vector to position my lift vector, such that I rotate the velocity vector 90 degrees in pitch and then rotate that vector by the angle of bank, which will result in a vector in the 'lift' direction. Unity has plenty of good support to rotate the transform, but I'm not trying to rotate my player, I just want Unity to compute the quaternion rotation for me. Here's what I've tried to do, but Unity is not treating the multiplication of my vector by quaternion as a true movement of the vector.

     //determine lift vector direction

     **Quaternion rotateLift1 = Quaternion.Euler (90.0f, 0.0f, subBank);**

// Quaternion rotateLift2 = Quaternion.Euler (0.0f, 0.0f, subBank); //rotate velocity vector to make lift vector

     **Vector3 liftVector = rotateLift1 * V;**

// Vector3 liftVector = Quaternion.FromToRotation(V, rotateLift1); // normalize lift vector // forward = forward.normalized;

     **liftVector = liftVector.normalized;**

     // multiply lift vector by lift magnitude to determine actual lift vector

     **Vector3 L = lift * liftVector;**

I've left some of my failed code attempts in, for further information. I've put the current code in bold. I really don't know what to do at this point, short of coding my own quaternion transform, which is a bit more than I care to take on, particularly as it seems as though Unity should have a simple solution. Any thoughts? Thanks!

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 AdamScura · Feb 11, 2014 at 09:18 AM 0
Share

$$anonymous$$aybe I'm stating the obvious here, but can you just use transform.up as your lift vector?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by gfoot · Feb 02, 2014 at 09:28 PM

The problem with the third line of your code is that Unity's Euler function applies the rotations in the wrong order for you. You can split them up into two calls and multiply them yourself whichever way you like, e.g.

 Quaternion.Euler(0, 0, subBank) * Quaternion.Euler(90, 0, 0)

or vice-versa.

Because Unity multiplies vectors on the right of quaternions, you can read this right-to-left as a sequence of rotations about the world axes - i.e. 90 degrees about the world X axis, then subBank degrees about the world Z axis - or from left-to-right as a sequence of rotations about local axes - i.e. subBank degrees about the Z axis, then 90 degrees about the new local X axis.

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 rich_seabirdsim · Feb 14, 2014 at 10:39 PM 0
Share

Sorry to take so long replying, but I just returned from a conference. Anyway, gfoot, I had tried reordering and breaking down the rotations in various ways, but the way unity 'multiplies' vectors, it is not a true rotation, and my recollection is that the scalar quantities actually multiply each other, and it just wasn't giving me the correct answer. $$anonymous$$y solution was to algebraically deter$$anonymous$$e the zero-bank lift vector, based upon it being orthogonal. Then I computed the quaternion myself and multiplied it out, and voila. @AdamScura, you might have saved me a few hours of math had I not already deter$$anonymous$$ed a solution. I haven't tested transform.up. I thought previously that all transform functions directly manipulated the transform, so I didn't read through all of them, but from what I could tell from the manual, it should work. I might change it eventually to clean it up and maybe improve processing, although Unity is likely computing a solution the same way. Thanks!

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

20 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

Related Questions

Rotate vector around vector? 2 Answers

Rotating a character's velocity? 3 Answers

Quaternion.Slerp only one axis? 1 Answer

Snap and align two cubes 1 Answer

Top down camera for object moving on sphere 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