like this?
gameObj.transform.eulerAngles.y = 180;
or
gameObj.transform.eulerAngles.y += 180;
like this?
gameObj.transform.eulerAngles.y = 180;
or
gameObj.transform.eulerAngles.y += 180;
In C# at least, I think you have to assign a value directly to the âeulerAnglesâ field, e.g.:
gameObj.transform.eulerAngles = new Vector3(
gameObj.transform.eulerAngles.x,
gameObj.transform.eulerAngles.y + 180,
gameObj.transform.eulerAngles.z
);
(Iâm pretty sure this is right, but I canât remember for sure at the moment.)
Also, your two examples are functionally different, so as far as choosing between them goes it just depends on what behavior you want.
All I had to do was really just you top answer, but instead of gameObj I put in a variable transform name. Like this:
pivot_Pan.transfor.eularAngles.y = 180;
You can rotate transforms with Rotate
You can assign Quaternion rotations to transform.rotation
You can assign a Vector3 to the transformâs eulerAngles
And what if I have an object, rotated by X axis by N degrees (unknown non-zero value) and I need to set it rotation strictly to R value in? The target result is not rotation by N+R or N-R, remember that we donât know N value, but we need to set rotation to known R.
transform.Rotate is appropriate in that case.
transform.Rotate(R, 0, 0);
No, it is not. He (and me too) want to SET the value to R, not add R to it.
Based on what you have, you can choose either you want. The one with just â=â is fine, but the other one is 1 + 180. You get what I am saying?
none of this works! it gives me the error:
cannot modify the return value of transform.eulerAngles because it is not a variable
CODE:
mc.eulerAngles.y = 100;
//i already entered the code
public Transform mc;
//and verified it as Main Camera
this guy said it right, it was the solution for me anyway
can anyone tell me how to rotate transform.rotate, with the up and down arrow key.
how to press a key an make the object rotate forward and backward in its local space.
The Unity API page for rotation shows you exactly that.
I kept trying different methods and came up with this, it worked for me (Unity 2018.2.5f1):
transform.rotation = Quaternion.Euler(0, 0, 45);
If you want to set rotation as Editor :
transform.localRotation = Quaternion.Euler(1,1,1);
This is what I was looking for thanks a lot
I donât know why but this is not working for me
i just want to change rotations on x and z to zero y must remain same. what do i put in yâs place?
Thatâs a harder question than you might expect, because Euler angles are pretty terrible in anything more complex than the most basic of applications. I have this longer writeup that I would highly recommend reading to clarify how.
You can plug in transform.rotation.eulerAngles.y to the second parameter of the above function, and it may work in some cases, but because the three Euler angles often all depend on each other in unpredictable ways, itâs not a good idea.
For setting Rotation or in other words, Set New Rotation to your transform.
transform.localRotation = Quaternion.Euler(0, 180, 0); //Set Rotation value of y to 180 and rest 0;