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 Intrawebs · Nov 12, 2012 at 07:04 AM · c#rotationtransform

Why is transform.LookAt backwards for my model?

I have an animated character I bought from the asset store. When I do the LookAt he looks exactly in the same direction that Im looking at, the result is his back is to me. The second line below works though, but, I would rather not have to do that hack and figure out what the problem is, any idea?

 //back facing
 transform.LookAt(target.transform);  
 
  //this works
  transform.rotation = Quaternion.LookRotation(transform.position - target.transform.position);
Comment
Add comment · Show 1
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 AlucardJay · Nov 12, 2012 at 09:26 AM 0
Share

So the model's forward is facing towards the negative Z-Axis? Unless you fix the model in a modelling program, or use an empty gameObject as a container for the model, you are stuck and have to work with your inverted LookRotation. (LookAt is not broken!)

2 Replies

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

Answer by Kryptos · Nov 12, 2012 at 09:30 AM

The fact that the second code works, show that your object is facing towards the negative z-axis.

The equivalent of transform.LookAt(target.transform) is Quaternion.LookRotation(target.transform.position - transform.position).

Thus you should fix your model. For example you can create a parent GameObject and add a 180-degree rotation around the y-axis.

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
avatar image
-1

Answer by deltamish · Nov 12, 2012 at 07:16 AM

Updated

given reason for change in the script and why the problem occurs

Anyways

Use this script to make the character look towards you

 public var target:Transform;
 public var rotationspeed:float = 2.0; 
 
 function Update(){
 var direction:Vector3 = target.position - transform.position;
 transform.rotation = Vector3.Slerp(transform.rotation,Quaternion.LookRotation(direction),rotationspeed * Time.smoothDeltaTime);  
 transform.eulerAngles = Vector3(0,transform.eulerAngles.y,0);
 }

NOTE You script has direction = transform.position - target.transform.position; this is causing your object to turn away.(This is like giving negative values)

Where as mine has target.position(you can also use target.transform.position) - transform.position;this makes the body to turn towards

the player or any object.(This is like giving positive values)

Comment
Add comment · Show 6 · 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 Intrawebs · Nov 12, 2012 at 08:43 AM 0
Share

What do I mean? "He looks away from me". Also, how is all that code better than the 1 line of $$anonymous$$e that actually works, and, this doesn't help me solve the problem as to why "LookAt" is broken in my use case.

avatar image deltamish · Nov 12, 2012 at 10:20 AM 0
Share

Cause transform.lookAt makes the object turn quickly whereas my code makes it turn smooth and slowly(more realistic).Try it just copy mode or edit your self

avatar image deltamish · Nov 12, 2012 at 10:24 AM 0
Share

if you want the object to trun a bit more quickly use Time.deltatime or change the rotation speed values

avatar image Kryptos · Nov 12, 2012 at 12:49 PM 0
Share

Cause transform.lookAt makes the object turn quickly

It does not "turn" quickly, it sets the rotation in one frame. Anyway the issue here is not related to the speed of the rotation but to correct the facing direction.

Your answer is interesting but off-topic.

avatar image deltamish · Nov 12, 2012 at 03:41 PM 0
Share

I have given answer to his rotation problem in the note section Sorry for my bad comment.i commented about rotation speed because He asked why did i replace transform.LookAt with my code. The script works , it makes the object to rotate towards the player or any object.

Show more comments

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

12 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

Related Questions

Flip over an object (smooth transition) 3 Answers

Saving coordinates and transferring them to the second object 1 Answer

How to rotate a projectile to face the player in 2D? 1 Answer

Rotate object around object with fixed value. 1 Answer

Rotating transform with custom space 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