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
2
Question by SergeantBiscuits · Sep 19, 2012 at 08:53 AM · camerarotationobject

Object Rotation Relative to Camera

Hey guys, fairly simple question:

I've got a menu system that consists of 2D planes in world space with a script that makes them always face the camera:

 function Update () {
 
     // Face the camera directly.
     transform.LookAt(Camera.main.transform.position);
     
     // Rotate so the visible side faces the camera.
     transform.Rotate(90, 0, 0);
     
 }

The planes are on a culling mask with a secondary camera so they render on top of everything else... fairly standard, looks like this at best (the icons/text are located around the turret, in world-space):

Menu from horizontal

Trouble is, when you view an object from a tilt above or below the horizontal, the rotation of the objects does not match the rotation of the camera view, ending up in a derpy situation such as this:

Menu from an angle

I need a way to keep the icons/text horizontal relative to the screen. Any idea how I could pull this off?

Thank you!

Comment
Add comment · Show 2
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 SergeantBiscuits · Sep 19, 2012 at 09:44 AM 0
Share

Thanks as always, Fattie! $$anonymous$$ike's solution worked but I'm investigating worldUp for future use.

I've been trying to figure out how to make a more natural placard orientation, but haven't managed to make it happen without parenting the plane to a something. Thanks for the tip though--I'll keep messin with it.

avatar image Fattie · Sep 19, 2012 at 09:51 AM 0
Share

$$anonymous$$ike has aced in, I'm too drunk - the "up direction" thing is a bit different, yes hope it helps one day !!

1 Reply

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

Answer by whydoidoit · Sep 19, 2012 at 09:21 AM

This might do it:

     transform.rotation = Quaternion.LookRotation(-Camera.main.transform.forward, Camera.main.transform.up);
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 SergeantBiscuits · Sep 19, 2012 at 09:42 AM 0
Share

That did the trick. Thanks $$anonymous$$ike!

http://imageshack.us/a/img404/4875/fixedv.jpg

avatar image elvirais · Dec 05, 2018 at 12:56 PM 0
Share

Still works (2018) :) thanks!

avatar image abenettaleb · Feb 07, 2019 at 10:50 PM 0
Share

Thx, Still works 2019, hhhhh

avatar image zenith_77 · May 11, 2020 at 08:19 AM 0
Share

I've trawled the internet look for the answer to this - and finally found it - thank you ever so much! :D

avatar image BlueBukkitDev · Aug 02, 2020 at 02:16 PM 1
Share

Looked everywhere for this line of code. Adjusted it to suit my 3rd-person perspective needs.

transform.rotation = Quaternion.LookRotation(new Vector3(Camera.main.transform.forward.x, 0, Camera.main.transform.forward.z));

Thank you so much. Still working in 2020.

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

16 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

Related Questions

Replicate rotation of Camera 1 Answer

Rotate object ON THE CAMERA UP AXIS 2 Answers

Make object appear within camera view 0 Answers

Help, please with rotation input 0 Answers

Wonky Camera Behaviours 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