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 chillypacman · Mar 16, 2012 at 11:54 AM · vectorcross

Getting vector which is pointing to the right/left of a direction vector?

If I have a vector such as (0,0,1) and I get its 'right' equivalent I should get something like (1,0,0), its left would be (-1,0,0), this is just the simplest case there may be more complex scenarios such as (0.2, 0.3, 0.5), so on and so forth.

Any ideas?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
8

Answer by aldonaletto · Mar 16, 2012 at 01:51 PM

In a 2D space - Vector2, or Vector3 with one coordinate fixed at 0 - you can get the right and left vectors with simple transformations:

  // original vector in the xz plane (y = 0):
  var forward: Vector3 = Vector3(0.5, 0.0, 0.8);
  // transformed vectors right and left:
  var right = Vector3(forward.z, forward.y, -forward.x);
  var left = -right;
For a full 3D vector, however, there's no predefined left/right directions - you must set some reference, usually the up direction. Having the up direction, you can calculate the right and left vectors using a cross product:

  // original vector:
  var forward: Vector3 = Vector3(0.5, 0.7, 0.8);
  // up direction:
  var up: Vector3 = Vector3(0.0, 1.0, 0.0);
  // find right vector:
  var right = Vector3.Cross(forward.normalized, up.normalized);
  var left = -right;
NOTE: I never remember the correct order of the Cross parameters; if the right vector is pointing to the left, just swap the parameters.
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 IntergalacticSloth · Oct 07, 2016 at 10:57 PM 0
Share

Thumb first!

Speaking of "The Left Hand Rule", the Vector Cross function takes the thumb parameter first. So I think your left and right are backwards :P


TEST: I threw this pretty little mess into an Update() of a script in order to check.

I also clicked 'Collapse' in the console... Played for a second, then stopped to read the console :P

         Debug.Log("We feed the cross 'Up' then 'Forward' and get: " 
             + "\n" 
             + Vector3.Cross(Vector3.up, Vector3.forward));
         Debug.Log("Now look! The world's 'Right' is also Vector: " 
             + "\n" 
             + Vector3.right);
         Debug.Log("Just as you would expect from your left hand." 
             + "\n");
         Debug.Log("What if we feed 'Forward' first, as the ''thumb''?" 
             + "\n");
         Debug.Log("Awkward hand position, but you get: " 
             + "\n" 
             + Vector3.Cross(Vector3.forward, Vector3.up));

avatar image
2

Answer by senad · Mar 16, 2012 at 12:51 PM

Use the vector cross-product: http://en.wikipedia.org/wiki/Cross_product

In the first case you would obtain it like this: bnrm = (0,0,1) x (0,1,0)

(although I am not sure if the sign would be right.) :D

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to move object using Vector3.Cross? 0 Answers

change the length of the vector 1 Answer

Vector 2 3 4 help 1 Answer

Vector based on the rotation of the main camera 1 Answer

Enemy and hero. Distance 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