Set rotation values equal to 0

I have an object that’s rotated around the y-axis (let’s say 0,30,0).
Is there any way I can set these values equal to 0? So I don’t want to rotate the object back to 0,0,0, but I want to set the rotation at 0,30,0 as a default rotation.

So in the script I want to set that the rotation values are now equal to 0,0,0 without changing the rotation/scale or position of the object.

Thank you very much!!!

Add this line to the Start() function…

transform.rotation = Quaternion.Euler(0, 30, 0);

That will make it start with that rotation.

Hi, as far as I understand: you want to rotate your object without rotating the transform component. That is, only rotate the mesh (I assume that object contains a mesh). I see 3 options:

  • modify the mesh before importing it: any 3D editing software will do this
  • modify the mesh itself by a script
  • Insert a new Transform as the parent of this object

Option 3 should be the quickest way to do it: create an object containing only the mesh as a child of the main object. Change the rotation of this child mesh to (0,30,0). The parent object still have 0 rotation and can contain all the scripts you need, be referenced by other object etc…

Option 2 would take place in the Start() of the object. You could get the vertices of the mesh using the MeshFilter component and rotate them. Create a Matrix4x4 from a TRS with only a (0,30,0) rotation. Use it to rotate the vertices by multiplying the vertices positions by the matrix, and set the vertices back to the mesh. You should then recompute the normals and the bounds (or rotate the normals with the matrix). Your script should be close to this one.

// put the following in where u like

transform.rotation.y = 0;

try Space.World as a 4th paremeter of Rotate method.

transform.Rotate(0, angle * 8, 0,Space.World);

I think you mean: YourGameObject.transform.localRotation = Quaternion.identity;