Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 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
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

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.

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

Offset raycast by specific amount 1 Answer

Angle between two vectors rotated by quaternion? 0 Answers

Changing the forward rotation for LookAt 2 Answers

Detecting when objects are facing each other 4 Answers

What could be the reason 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