Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
12
Question by oliver-jones · Nov 19, 2011 at 08:37 PM · rotationtransformquaternionslerp

Add 90 Degrees to Transform.Rotation

Hello,

Haven't been using Unity for a while and I've kind'a forgotten a few simple things, basically I'm using a 'LookAt' technique by using a transform.rotation = Quaternion.Slerp.

     var lookPos = target.position - transform.position;
     lookPos.y = 0;
     
     var rotation = Quaternion.LookRotation(lookPos);
     var adjustRotation = transform.rotation.y + rotationAdjust;
     
     transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);

The only thing I want to do I to add an extra 90 degrees to the transform rotation because the transform doesn't actually look at 'rotation', its 90 degrees off.

Cheers

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
76
Best Answer

Answer by aldonaletto · Nov 19, 2011 at 09:02 PM

You can't modify the components of transform.rotation directly: this property is a quaternion, and its components have nothing to do with the familiar x, y, z angles that appear in the Inspector/Transform/Rotation (these are actually the eulerAngles).

In this case, you should multiply the lookAt quaternion by a 90 degrees rotation - in the quaternion world, multiply actually means combine. Supposing you need this extra rotation around the Y axis, you could do the following:

 var lookPos = target.position - transform.position;
 lookPos.y = 0;
 var rotation = Quaternion.LookRotation(lookPos);
 rotation *= Quaternion.Euler(0, 90, 0); // this adds a 90 degrees Y rotation
 var adjustRotation = transform.rotation.y + rotationAdjust; //<- this is wrong!
 transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
Comment
Add comment · Show 7 · 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 Hamesh81 · Mar 16, 2012 at 06:21 AM 1
Share

Thanks aldonaletto, this helped me a lot as well!!

avatar image Infrid · Jul 03, 2013 at 03:06 AM 1
Share

I don't know how I missed this little gem.. I had just about given up on trying to modify quaternions. Thank you so much aldonaletto - you've opened a huge and important; and as to just now locked door for me. Very grateful.

avatar image lalamax3d · Dec 10, 2013 at 06:22 PM 0
Share

aldonaletto. you are a great man sir.

avatar image jpizzle · Jan 24, 2016 at 07:44 PM 0
Share

what is target.position?

avatar image Guhanesh · Mar 25, 2016 at 10:50 AM 0
Share

not working for me.

 targetRotation2 *= Quaternion.Euler(0, -90,0); 
 print(targetRotation2.eulerAngles);

targetRotation2.eulerAngles is always (0,0,0) no change.

Show more comments
avatar image
1

Answer by Vollmondum · Dec 15, 2015 at 02:48 AM

Easier solution:

 transform.Rotate(Vector3.right, 90, 1);

Not sure if that's correct in that Quaternion world (I really tried to understand, but that's too complicated), but works for me.

"right" actually rotates 90 on X, thus pick which you need (up, back etc.)

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 rodude123 · Jul 25, 2017 at 12:19 PM 0
Share

Quaterion gives a more accurate value than just using your method and thus making it smoother

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

15 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

Related Questions

How to get Angle float of specific axis.(Turret clamping related). 2 Answers

Get slerp to work just as LookAt(,Vector3.right) does 1 Answer

Rotation of an object with quaternion 1 Answer

Choppy rotation of character around y-axis 1 Answer

i want to get my to cube to rotate 90 degrees on the x-axis as it jumps 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