• 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 Ariel J · Jul 11, 2010 at 02:18 AM · transformvector3lookatx-axis

How to use x axis for transform.LookAt

I'm using a skinned mesh with bones in it. I've been trying to make one bone's negative x axis look at another transform, but when I use transform.LookAt, it uses the positive z axis.

How can I change this?

Thanks,

Ariel J

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

4 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by qJake · Jul 11, 2010 at 02:35 AM

You can't. The "forward vector" of any object is when the Z-axis is pointing at it (just like when you're looking at something, you're facing forward). This behavior cannot be changed.

You're probably going to need to do the math manually to rotate the object how you want it, unless you explain your problem more in-depth (perhaps in another question, since it would probably be unrelated).

Comment
Ariel J
Keseio

People who like this

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

Answer by CiberX15 · Dec 10, 2017 at 05:58 AM

Sorry, I know this is an old thread but I figured I would offer my solution to this problem. You know LookRotation will return a rotation pointing from the front of the object, so you just need to rotate it 90° on the Y axis to get a Quaternion that looks at your target with the X axis. In code it would look like this:

 Quaternion XLookRotation = Quaternion.LookRotation(dir, transform.up) * Quaternion.Euler(new Vector3(0, 90, 0));

You can of course modify the vector to point any axis or combination of axis towards the target object :)

Comment
adamgryu
BogdanDude
wolilio

People who like this

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

Answer by Anxo · Sep 13, 2010 at 07:40 AM

I have the problem sometimes. What I do is I create an empty game object that is facing in the direction I need it to. Then I make the object that needs to face that way a child of the empty game object and orientated it how I like. Place your code on the Empty Game Object and it will use the Z axis of the empty game object to rotate your object.

Comment

People who like this

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

Answer by Krnitheesh16 · Dec 21, 2022 at 07:55 AM

Try this!

 Vector3 target = TargetObj.position;
 Vector3 direction = new Vector3(target.x - transform.position.x, target.y - transform.position.y);
 transform.right = direction;
Comment

People who like this

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

Update about the future of Unity Answers

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta later in June. Please note, we are aiming to set Unity Answers to read-only mode on the 31st of May in order to prepare for the final data migration.

For more information, please read our full announcement.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Rigidbody to follow player around 1 Answer

How to prevent Z axis rotation ? 0 Answers

Help!!! Transform controls problem for a plan-view air hockey game. 0 Answers

transform.LookAt boundaries 1 Answer

What is the algorithm to assign to transform.right? 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