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.
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.
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.
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
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).
Answer by Nicolas_Granese · May 28 at 04:09 PM
Hello, @Lionmeow,
See if the transform1 has the same gameObject of the transform2, please.
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.
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
![](https://koobas.hobune.stream/wayback/20220613061035im_/https://answers.unity.com/themes/thub/images/avi.jpg)