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 daniazram · Oct 08, 2015 at 10:53 AM · unity 5

Understanding transform.LookAt()

Hi all! I was trying to make the face of my character to look at some target, I used lookat function but it was always rotating the head in some other direction and head was never facing the target, but when I tried this on cube the cube rotates exactly the way it should. Then I made the head child of an empty gameObject and pass the empty parent gameObject as head and everything worked fine. So my question is what was the problem before making this parent child realtionship? Thanks in advance.

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
2

Answer by Bieere · Oct 08, 2015 at 05:46 PM

So essentially the LookAt() function takes a transforms forward, and points it towards another transforms current World Position.

So if your transform you're trying to rotate to lookat something has its front not on the forward Vector, it might give you a weird rotation similar to what you're experiencing.

So the child parent setup you mentioned is likely the easiest way to solve your issue, now if you're up for doing some Vector maths, you could correct your rotation issue.

Comment
Add comment · Show 3 · 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 daniazram · Oct 12, 2015 at 09:55 AM 0
Share

Sorry for my late answer, so I understand that the forward vector of both(target and the head) should be same(head's forward should be in the direction of target's forward, correct me if I am wrong), you mentioned vector math what kind of vector math do I need I mean what methods are there that can help me in this thing. Basically I was trying to do I$$anonymous$$ on arms to hold the gun I had done very good so far but still having some issues. Hands are not exactly holding the gun the rotate very well like a real human arm but they don't hold the gun properly like if gun is at (5, 1, 5) they will try to approch (2, 1, 5). So hands will try to reach left side or right side of the gun but not the gun.

avatar image Bunny83 daniazram · Oct 12, 2015 at 12:19 PM 0
Share

Uhm, no. The forward vector of your target is completely irelevant.

Just draw an imaginary line between your player position and your target position. LookAt will rotate your player so the players blue arrow (the forward vector) points along this imaginary line, so it points at your target. If the transform of your head doesn't have the blue axis sticking out of the characters nose (but ins$$anonymous$$d at the top / bottom / the sides / back), LookAt will of course rotate the wrong side towards the target.

If you want to use LookAt with an object that is incorrectly rotated, you can insert another empty child object in between to fix the rotation:

  • Add an empty GameObject to the same parent that your head is attached to. $$anonymous$$ake sure it's positioned at the same point where your head is located.

  • Rotate the empty GO, so that the blue axis points out of the characters face and the green axis points upwards (red should point to the characters right side).

  • Once it's rotated correctly, just move the Head object inside the empty GameObject.

  • Now make sure when you want to rotate the head to rotate the empty GO ins$$anonymous$$d of the actual head.

avatar image daniazram Bunny83 · Oct 12, 2015 at 12:30 PM 0
Share

Thank you so much I was thinking the whole time that target and head both should have there forward vectors in the same direction and your answer cleared my concepts pretty much. I think I should post another question to clarify I$$anonymous$$ concepts and some vector maths.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Optimization of the game and Viking Village asset 2 Answers

How do i code a Mesh collider ? 1 Answer

Two instances of Unity3D 5 0 Answers

Button Enabling/Disabling using Collision Triggers? 1 Answer

Unity 5 standard shader problems on Android 0 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