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
1
Question by Caiuse · Oct 29, 2010 at 03:01 PM · camera

Rotating an object to face the camera regardless of the cameras position.

Okay so far I have this script, this automatically faces the object towards the camera

var target : Camera; function Update() { var n = target.transform.position - transform.position; transform.rotation = Quaternion.LookRotation( n ); } 

I want to know how to edit this script to give the object a 90 tilt to it always.

Cheers - C

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

3 Replies

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

Answer by VS48 · Oct 29, 2010 at 03:35 PM

On which axis should the 90-degree tilt be?

Update your code and change:

transform.rotation = Quaternion.LookRotation(n)

To:

transform.rotation = Quaternion.LookRotation(n) * Quaternion.Euler(0, 90, 0);

If that's not the right direction, just change the parameters of Euler() depending on your axis and direction of rotation; maybe Euler(90,0,0) or Euler(0,-90,0), etc.

Edit: Slowly change direction

var newRotation = Quaternion.LookRotation(n) * Quaternion.Euler(0, 90, 0);
transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, Time.deltaTime * 1.0);

Not sure if that's what you're asking for, but hope it helps... Change 1.0 to control easing speed.

(Note, since it's interpolating from the current rotation, it is not linear, though that's often not desired anyway)

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 Caiuse · Oct 29, 2010 at 05:38 PM 0
Share

Thanks a lot, Got another quick question, after a curtain point can i get my plane to flip around, so its always facing the right direction.

avatar image VS48 · Oct 29, 2010 at 09:51 PM 0
Share

No prob! Sorry -- not sure what plane you mean -- see my edit if you mean you want to change the direction slowly over time.

avatar image Caiuse · Oct 30, 2010 at 08:54 PM 0
Share

Thats useful, but what i mean is I have a sphere with a small "plane" arrow pointing down to it, the camera orbits the sphere all around but after a certain point the arrow disappears "inside" the sphere.

avatar image
4

Answer by skovacs1 · Oct 29, 2010 at 04:23 PM

If you wanted to face the camera, wouldn't it just be easier to do something like:

var cam : Camera;

function Update() { transform.LookAt(cam.transform); }

And for your tilt, your object's axes are probably misaligned.To maintain the orientation of your misaligned axes, you could do something like:

var cam : Camera;

function Update() { transform.LookAt(cam.transform, transform.up); }

or with your posted code, merely change your LookRotation to this:

Quaternion.LookRotation(n, transform.up);

You really should however fix your misaligned axes or they will likely cause you more problems in the future.

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 leith · Oct 29, 2010 at 05:16 PM

I get the impression what is meant is that the "roll" of the object is 90 degrees off. In which case, using a "look at" along with an up vector from the camera is probably what is needed.

something like:

obj.transform.LookAt(cam.transform.position,cam.transform.up);

And if that "up" is the wrong up, change the up vector to the camera's left or right, etc.

obj.transform.LookAt(cam.transform.position,cam.transform.left);

the above is pseudo-code. untested.

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

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

2 People are following this question.

avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Use lookAt and transform.translate at the same time 1 Answer

FPS Camera moving by my left mouse button 1 Answer

More Effective Camera Switching 1 Answer

How can i fix the camera in multiplayer game? 2 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