• 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
9
Question by superventure · Jun 21, 2011 at 12:04 AM · cameratransformlookat3dtextreverse

LookAt in opposite direction?

I don't understand why 3dtext has backwards orientation, but I need to use transform lookat with the text mesh. I don't want to dump it in a another game object, I just need to look at the camera, without the letters being backwards! How do I reverse transform.LookAt?

Thanks alot!

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 Eric5h5 · Jun 21, 2011 at 12:51 AM 1
Share

The orientation isn't backwards, though. Having it look at the camera would mean the forward vector is facing towards the camera. This is only "backwards" because you've rotated it 180 degrees from the way it would normally be facing.

2 Replies

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

Answer by superventure · Jun 21, 2011 at 12:11 AM

Found an answer after more browsing (sorry)

transform.LookAt(2 * transform.position - stareat.position);

Comment
Add comment · Show 5 · 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 Bunny83 · Jun 21, 2011 at 12:15 AM 0
Share

Yep, that will work too ;)

avatar image aanimation · May 22, 2014 at 05:06 AM 0
Share

yeaah..thanks..its working

avatar image rodichan · Jan 28, 2016 at 09:38 PM 0
Share

Serious question: why does multiplying by two work? I've tried this solution in a project and don't understand the math behind it.

Thanks!

avatar image Bunny83 rodichan · Jan 29, 2016 at 03:18 AM 3
Share

Simple vector math. To get a direction vector from a point to another you do "target - start". In this case we calculate a direction vector from the object we want to look at (stareat.position) to our own position. So the resulting relative direction vector points towards us.

By adding our own position to that vector we let the direction vector start at our position. Since the direction points towards us it will be result in the position behind us.

ReverseLookAt

In this image we are the red dot (p1) and our second object is the green dot (p2). So instead of using p2 as lookat target we use p3 which is exactly behind us (the red dot). You get p3 by using the blue direction vector from p2 to p1 and adding it to p1.

 p1 + (p1-p2) == p1 + p1 - p2 == 2*p1 - p2

Another way to look at it is this:

reverselookat2

reverselookat.png (6.2 kB)
reverselookat2.png (3.2 kB)
avatar image Bunny83 · Jan 29, 2016 at 03:47 AM 1
Share

Maybe i should add that this solution is actually more complicated than mine below. LookAt most likely uses LookRotation internally. It simply subtracts it's own position from the given point to get a direction vector towards the target. So if you pass

 2 * transform.position - stareat.position

and LookAt subtracts transform.position from that given vector it would be

 2 * transform.position - stareat.position - transform.position

which is just

 transform.position - stareat.position
avatar image
24

Answer by Bunny83 · Jun 21, 2011 at 12:14 AM

That will do what you want. It rotates the transform "away" from the target.

 var target : Transform;
 function Update ()
 {
     transform.rotation = Quaternion.LookRotation(transform.position - target.position);
 }
Comment
Add comment · Show 1 · 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 yotingo · Jun 28, 2014 at 08:34 AM 0
Share

Thanks for this!

I was trying to figure out how to do it with Quaternion.LookRotation specifically. This works perfect!

I can't believe it was as simple as swapping the transform and the target.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

Attaching camera to instantiated object 1 Answer

make player move in camera direction 1 Answer

Smoothly Move camera while looking at object 0 Answers

LookAt only when camera position changes 2 Answers

An alternative to RotateAround for collisions 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