• 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
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
Hamesh81
2dkot
Vollmondum
3lions
klesun
peterpunk
Fawds
gregroberts
drginm
michaelhsiu101
jacksonkr
Kokowolo
_TheFuture_
Zusei

People who like this

14 Show 0
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

  • Sort: 
avatar image
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
Toji
Hamesh81
syclamoth
2dkot
lalamax3d
Sildaekar
samsmithnz
drudiverse
Dubious-Drewski
Arkade
CharlieTM
oktemre
WhoIsRich
PhoenixRising1
klogd
And 68 more...

People who like this

81 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

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
Coulomb1

People who like this

1 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

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

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

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

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

Setting an objects angle about a local axis without localEulerAngles? 0 Answers

Rotating a certain axis offsets the other ones? 1 Answer

Weird issue with fire angle of projectiles changing 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