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
0
Question by HammerBG · Mar 30, 2013 at 10:13 PM · rotationtransformlookat

Using LookAt method to get object X rotation to face another object

I have a object that i want to rotate only on its X axis to "look at" another object. But i think i have imported it incorrectly. It is a ship model that i want to rotate to point to the object that its traveling to. This is what i basically do: this.gameObject.transform.LookAt(this.destination.transform.position); But instead of the source object to "look at" the destination, the object's X rotation is way off.

Help please :)

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by robertbu · Mar 30, 2013 at 10:20 PM

It is most likely the model. Place a small sphere at the origin. Then take your model and set the position and rotation to (0,0,0). The sphere should be inside your ship at the center of its rotation, and the front of your ship should be facing positive 'z'. If either of these two are off, then you need to fix things. The best way is to fix it in the modeling program, but you can fix it by placing an empty game object at the origin, placing the ship at the origin with the front facing positive 'z', then making the ship a child of the empty game object. Your rotation/position code is then applied to the empty game object. This does not work for all situations of offset position/rotation, but it can work for many of them.

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 HammerBG · Mar 31, 2013 at 09:10 AM 0
Share

I've tried adding an answer to your suggestion, but it seems lost ... anyway. The sphere is in the perfect center of the object.

The object with 000 rotation looks like this:

link text

But when i use the lookat code the rotation is way off:

alt text

Since what i am doing is a 2.5d project, i believe only rotating on the Z axis should be enough (and considering the destination and the rotating object share the same Z coords), but for some reason it is not taking under consideration the Z axis at all.

avatar image robertbu · Mar 31, 2013 at 01:40 PM 0
Share

Forward is always positive 'z'. So if your camera is in the default position (looking at forward 'z'), then it is the side of your ship we do not see which is forward (which is exactly what you see in the this photo). As mentioned above, you can "fix" this by:

  • placing an empty game object at the pivot of the ship (i.e. where the sphere was placed).

  • Rotating you ship so the nose is facing positive 'z' with the top of your shop up (facing positive 'y').

  • $$anonymous$$ake your ship a child of the empty game object by dragging and dropping the ship on the empty game object.

  • Place your code with the LookAt() or LookRoataion() on the empty game object.

avatar image HammerBG · Mar 31, 2013 at 02:47 PM 0
Share

This seems to work, although a bit hacky. Since i have the original 3ds file, can you recommend a read that covers how to fix this issue in the modeling program?

avatar image HammerBG · Mar 31, 2013 at 03:51 PM 0
Share

I think i have found the solution, basically i changed the pivot points of the object in max to be the way you suggested, i.e. the nose to face positive Z and the "up" to face positive Y. Then when exporting to fbx select "Y-up" and that's it!

Thank you Robert!

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

10 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

Related Questions

LookAt Translation Not Sticking 1 Answer

Lock rotation axis? 4 Answers

Joint Transform Rotation in Unity? 0 Answers

transform.LookAt issue 1 Answer

How do I get GameObjects to look at me? 2 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