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 oliver-jones · Oct 07, 2013 at 02:32 PM · camerarotationguiplane

Problem - Getting Object to Face Camera Plane

Hello,

I'm using this code:

 var rotation = Quaternion.LookRotation(-Camera.main.transform.forward);
 transform.rotation.y = rotation.y;

To get my GUI objects to always face the plane direction of my camera, works fine until I reach a certain angle, which is about 170, lower than this and the GUI doesn't move, unless I keep pivoting around, and then it will 'snap' facing the camera again at an angle of 289.

Any reason why it is doing this?

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

2 Replies

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

Answer by whydoidoit · Oct 07, 2013 at 03:50 PM

Your problem is that you are trying to set the Y of a Quaternion - you shouldn't fiddle with the elements of a quaternion directly - you probably mean to use the eulerAngles. The y of a Quaternion is not the rotation about the y axis.

Comment
Add comment · Show 2 · 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 oliver-jones · Oct 07, 2013 at 03:52 PM 0
Share

So how do I use 'LookRotation' without using Quaternion?

avatar image oliver-jones · Oct 07, 2013 at 03:58 PM 0
Share

Okay, all I did was this:

 transform.forward.x = Camera.main.transform.forward.x;
 transform.forward.z = Camera.main.transform.forward.z;
avatar image
0

Answer by raimon.massanet · Oct 07, 2013 at 02:43 PM

Why not use tranform.LookAt instead?

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 whydoidoit · Oct 07, 2013 at 02:48 PM 0
Share

That doesn't work. See http://unitygems.com/quaternions

avatar image oliver-jones · Oct 07, 2013 at 03:24 PM 0
Share

@whydoidoit After reading the link you posted, I believe what my problem is, is: Gimbal lock effect. When one rotation aligns with another, they get locked together and one dimension is lost.

avatar image raimon.massanet · Oct 07, 2013 at 03:30 PM 0
Share

I believe transform.LookAt should work for UI elements facing a camera... @whydoit Can you point me to the section that states otherwise in the link you posted?

avatar image oliver-jones · Oct 07, 2013 at 03:40 PM 0
Share

The problem with using LookAt is this (the red boxes are GUI elements within my scene, this is looking top down at the scene), plus, I only want the elements to rotate on the Y axis:

alt text

avatar image whydoidoit · Oct 07, 2013 at 03:53 PM 0
Share

It's the bit about how to get objects to point at the camera - the camera is a point in space so LookAt only works at significant distance. The items should point at the inverse of the the camera's forward, not at it's position.

See the bit where it says this:

When you get close to the enemies you see that there is another problem, the Zzzzzz aren't pointing outwards from the screen. A lot of people are confused by this (I know I was) - we have a script that says LookAt the camera - why isn't it looking at it?

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

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

Related Questions

Rotating a plane so that its top is parallel to the camera viewport 1 Answer

Camera Loop Rotation 0 Answers

Attach image to button 1 Answer

Bind horizontal scrollbar to camera control 1 Answer

3D effect with new UI system 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