changing obj angle and resetting it

I have a children transform rotation set to (0,0,0) at start, I want to change it to (x,0,0) after I down a button, and back to (0,0,0) when I release it.

I did transform.Rotate(x,0,0); and it works, but transform.Rotate(0,0,0) doesn’t work for resetting it, it just keep adding up the x for some reason. How do I reset to it back to it default rotation? (note I’m only changing the x rotation relative to the obj location

transform.Rotate, how to say, is kind of a verb. It does something. I mean this function ROTATE something on a certain amount of degrees. When you say Rotate 0, nothing just happens, because it tries to rotate the object on 0 degrees. If you want to set up a specific rotation, then you should use:

transform.rotation = new Quaternion.Euler(x, 0, 0);

There should be an error, because it should not keep adding up the x, but adding just nothing. Thus, you have somewhere an error. I would suggest that it is in the IF statement, where you check the keyboard.

I think he means it just rotating every time the button is pressed. As you pointed out rotate by 0 does nothing, so each press is doing +x.

Getting an error with adding “new” before quaternion. I just want to reset it back to 0 after the function (since it increase before the function

Oops! I am sorry, my bad. “New” is not needed in this case, indeed.

transform.rotation = Quaternion.Euler(0, 0, 0); // Reset rotation to 0

Btw, you also can Rotate it back with -x instead.

transform.Rotate(-x,0,0);

for some reason, my y rotation keep on changing even tho when I dont want it to change
set angle

m_FireTransform.rotation = Quaternion.Euler(-shootAngle, 0,0);

reset

m_FireTransform.rotation = Quaternion.Euler(0, 0, 0);

Show the script. Probably the problem is somewhere there.

edit: nvm fix it, all I had to do was change the angle at which velocity was added to the rigid body