localEulerAngles without parent transform

Hi there

I am stumped while trying to set the z-axis of the local rotation of a cube to zero. I cant use Rotate, because I dont know what the rotation on the z is going to be, so I wouldn’t know how much to add or subtract to get to zero. Also, Unity docs says that localEulerAngles will set to the rotation of the parent and my gameObject does not have a parent transform. Why is it that the Unity Engine does not provide a simple solution for such a basic function? I have looked at the docs for each rotation function and cant find anything that is specific to true local rotation.

I’m sure I can store the current local rotation in a var and then do a subtraction on something, but not sure how to.

Please help someone and thanks in advance!

If your gameobject doesnt have a parent, it is the parent.

There are plenty of simple functions that do what you want.

You can specify a Euler angle which is easier to understand.

transform.locationRotation = Quaternion.Euler(0,0, 90);

Thanks James. I have tried that, but it still rotates the transform based on global rotation. My understanding was that for a transform without a parent, the world becomes the parent? Is that incorrect?

If an object has no parent, localEulerAngles and eulerAngles are the same thing.

–Eric

Let me just double check my code again, it is quite complex and there might be something else wrong