Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
8
Question by ina · May 05, 2011 at 06:05 AM · rotationobjectvectoraxes

Aligning an object's rotation direction to a vector

How do you align an object's rotation direction to a vector?

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
20
Best Answer

Answer by Mike 3 · May 05, 2011 at 06:11 AM

transform.rotation = Quaternion.LookRotation(directionVector);
Comment
Add comment · Show 4 · 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 ina · May 05, 2011 at 07:29 AM 0
Share

what do you do if the object's axis is off by "90" degrees?

avatar image Koyemsi ina · Dec 03, 2020 at 03:53 PM 0
Share

Not sure to understand the question, but you can try Quaternion.FromToRotation() to change some direction into another, or differently said, to change the object's reference axis.

For example :

transform.rotation = Quaternion.LookRotation(directionVector) * Quaternion.FromToRotation(Vector3.right, Vector3.forward);
avatar image roamcel · Jul 28, 2011 at 12:56 PM 0
Share

I still haven't found an answer to that very question, ina

avatar image Fenyx · Feb 28, 2015 at 03:17 PM 2
Share

This worked for me;

 private Quaternion _facing;
 
 void Start () {
     //Grab the offset at the start.
     //You could also make your own Quaternion but don't use Euler angles it just seems to break things.
     _facing = transform.rotation;
 }
 void Update () {
     var rotation = Quaternion.LookRotation(directionVector.normalized);
     rotation *= _facing;
     transform.rotation = rotation;
 }
 
avatar image
3

Answer by iwaldrop · Mar 23, 2012 at 08:42 AM

To rotate an object to face a desired orientation, perform the following on LateUpdate():

transform.Rotate(Vector3.right/up/forward, float);

ex:

void LateDraw() { this.transform.Rotate(Vector3.up, 90); }

this will set the rotation each frame to whatever you need it to be. The example illustrates a 90˚ since that's the rotation offset of most imports...

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

Make an object rotate to face the player (but only on x and z axes) 2 Answers

Rotating a direction Vector3 by Quaternion 2 Answers

Unity touchpad not working to rotate an object 1 Answer

Smooth camera rotation on mobile and pc when GetMouseButton()? 0 Answers

How to keep local rotation when using raycasts? 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