• 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 /
  • Help Room /
avatar image
0
Question by Lionmeow · May 27 at 12:27 AM · rotationeulerangles

Quaternion.Euler is persisting into other values

I have some basic code that should, in theory, rotate one transform to one value, and the other to another value.

     transform1.rotation = Quaternion.Euler(0f, someValue, 0f);
     transform2.rotation = Quaternion.Euler(0f, 0f, 0f);

This should be working. However, what ends up happening, is that it acts like:

     transform1.rotation = Quaternion.Euler(0f, someValue, 0f);
     transform2.rotation = Quaternion.Euler(0f, -someValue, 0f);

It seems that whichever rotation comes first leaks into the second one in this manner. If I reverse the order and set transform2's rotation first, then transform1 gets its values set to the negative of transform2's. I don't understand why this is happening, but it is a big issue.

Comment
Add comment · Show 6
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 WolverineLight · May 27 at 03:10 PM 0
Share

Hello Lionmeow,

Rotations can be quite tricky. May I look at some broader code of yours? How do you plan to rotate one transform to another? - Meaning, are you changing 'someValue' over time?

Here is an article that may help: Quaternion.Lerp

Lerp is really useful because it automatically rotates objects for you over time, at whatever speed you need.

avatar image Lionmeow · May 27 at 06:20 PM 0
Share

Broader code wouldn't help me to solve this issue, considering it happens regardless of what else I put in the method. Even if I change someValue to an explicit value, e.g., do this:

  transform1.rotation = Quaternion.Euler(0f, 4f, 0f);
  transform2.rotation = Quaternion.Euler(0f, 0f, 0f);

It still ends up acting like:

  transform1.rotation = Quaternion.Euler(0f, 4f, 0f);
  transform2.rotation = Quaternion.Euler(0f, -4f, 0f);

So I'm really confused. There literally aren't any other scripts in the project at this point in time, so it can't be another script setting transform2's rotation.

avatar image WolverineLight Lionmeow · May 27 at 06:32 PM 0
Share

EDIT: I apologize, after reading your question again, I think I know what's going on. If you are trying to set a rotation, but it is seemingly backwards, there are a variety of ways to fix it. It could be there is an issue with parent/child rotation - a child follows a parent in terms of transformations. Or, you could simply put (0,-someValue,0) instead of (0,someValue,0). Hope that helps.

Setting transform1.rotation to Quaternion.Euler(0f, 4f, 0f) will set the rotation of that object to (0,4,0), period. It does not have any effect on transform2.rotation, and transform2.rotation does not affect transform1.rotation. If you could share more of the script, that would be great, and I can help you reach your goal.

Here is how I might set it up:

 void Update(){
 
 transform1.rotation = Quaternion.Lerp(transform1.rotation, transform2.rotation, 0.5f);
 
 }

Source: https://docs.unity3d.com/ScriptReference/Quaternion.Lerp.html

avatar image Lionmeow WolverineLight · May 27 at 07:12 PM 0
Share

This is ALL of my code:

 void Update()
 {
     transform.eulerAngles = new Vector3(0f, 4f, 0f);
     cameraTransform.eulerAngles = new Vector3(0f, 0f, 0f);
 }

However, it is still setting cameraTransform.eulerAngles to (0f, -4f, 0f).

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Nicolas_Granese · May 28 at 04:09 PM

Hello, @Lionmeow,

See if the transform1 has the same gameObject of the transform2, please.

Comment
Add comment · Show 2 · 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 Lionmeow · May 28 at 04:17 PM 0
Share

They do not have the same GameObject. Although I will note that transform2 is a child of transform1. But that most likely wouldn't explain why transform2 is getting the negative rotation of transform1.

avatar image Nicolas_Granese Lionmeow · May 28 at 04:48 PM 0
Share

If you want to rotate the children, try using transform.localRotation. And rename your variables ( like transformParentName and transformChildName ) for better readability and debugging.

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

232 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 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 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 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 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 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 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 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 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 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 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 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 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

copy rotation script doesent copy the full 360 degrees? 0 Answers

Help with suns rotation 0 Answers

Instantiate object in orientation of previously instantiated object 1 Answer

UI compass pointing to a 3D object 0 Answers

Quaternion.Euler doesn't work right? 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