• 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
Question by alejo1099 · Apr 22, 2018 at 01:36 AM · rotationvectors

Problems with the orientation of an gameObject

Good evening everyone, I have a problem, and it is the one shown in the gif https://drive.google.com/file/d/1zbqrpi5uPyEKfNduKvPjHEyKZnZzvz0L/view?usp=sharing , the selected blue object is right(derecha), and the green is left(izquierda) , what the cube does is point to the direction generated by the vector between right and left (as shown in the code). Now the blue line would be the forward or where you should point the box to maintain the orientation. This problem occurs when I put right or left over the other, or in other words, when the product point of the vector generated between right and left and Vector3.up, is close to 1, so it is almost parallel to Vector3.up. What I want to do is that the blue vector maintains its orientation. Beforehand thank you very much.

 private void Update()
     {
         Vector3 posRight = right.position;
         Vector3 posLeft = left.position;
 
         Vector3 vectorX;
         if (posRight.y > posLeft.y)
             vectorX = (posRight - posLeft).normalized;
         else
             vectorX = (posLeft - posRight).normalized;
 
         float dot = Vector3.Dot(vectorX, Vector3.up);
 
         print(dot);
 
         vectorForward = (posRight - posLeft).normalized;
 
         Vector3 halfPos = Vector3.Lerp(right.position, left.position, 0.5f);
         transform.position = halfPos;
 
         Quaternion rotLook = Quaternion.LookRotation(vectorForward);
 
         Debug.DrawLine(posRight, posLeft, Color.red);
 
         posRight.y = posLeft.y = transform.position.y;
 
         Vector3 directionForward = (posLeft - posRight).normalized;
         directionForward = Quaternion.Euler(0, -90, 0) * directionForward;
 
         Debug.DrawRay(halfPos, directionForward, Color.blue);
 
         transform.rotation = rotLook;
     }
Comment

People who like this

0 Show 0
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

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

Rotate vector A around vector B until it is perpendicular to vector C 2 Answers

Instantiating Platforms between two Vectors 1 Answer

Rotating tank barrel on X axis while the parent Turret rotates on Y axis 2 Answers

Vector Alignment and Spacing 1 Answer

Flip over an object (smooth transition) 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