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 MarcW · Nov 28, 2013 at 05:21 PM · rotationquaternionrotatenewbie

Rotate an object relative to Camera

I have a cube that I am rotating with the keyboard, like so (inside update() )

 // Get delta from inout
 Quaternion rotX  = Quaternion.AngleAxis (Input.GetAxis ("Horizontal") * rotationSpeed, Vector3.right) // X rotation
 
 // Apply rotation
 this.transform.rotation *= rotX;

 // Do the same for Y…


When I press left, the object rotates to the left as expected, the same goes for right. However when I move my camera around the back, pressing left makes it rotate right, and pressing right makes it rotate left. I figured out that if I work out the rotation between the camera and the object, I should be able to subtract this from my overall rotation and get the difference (works on paper) but I can't seem to figure out how to implement this in code. The nearest I can get is to make my object always face the camera :-(

I would like the left key to rotate "left" no matter the camera position (and of course to work with the Y and Z axis, as I intend to replace the keyboard with a LapMotion device).

Any suggestions?

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 MarcW · Nov 29, 2013 at 11:31 AM 0
Share

Thanks Subhajit, that got me to my final solution which was to use Camera.main.transform.right rather than Vector.right - thanks again!

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Subhajit-Nath · Nov 28, 2013 at 05:30 PM

If you need opposite rotaton, try Vector3.left instead of Vector3.right.

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
0

Answer by andreasng_pd · Nov 24, 2018 at 12:09 PM

Hey this is not a thorough answer. I think what is needed is a way to make objectA rotate around objectB(camera) up axis, for example. I'm currently searching the same thing, and many none-answers pop up.

So if the camera is one its head, and you press right, the object will rotate around the cameras local Y axis, and therefore, relative the the world, rotate the "wrong" way.

etc

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

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

Related Questions

How to always rotate clockwise 1 Answer

New to Unity: Trying to (loosely) simulate animal flight with separate buttons for each wing... 0 Answers

IMU Sensor and Quaternion 2 Answers

Top down camera for object moving on sphere 1 Answer

How do I rotate Z axis based off mouse click and drag? 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