This code doesn’t assign anything to an object’s rotation. Are you actually assigning a transform.rotation to that? Because when I do that sort of thing, it doesn’t happen relative to the parent.
But even if it did, you could just multiply the inverse of the parent’s roation, times whatever that gives you.
using UnityEngine;
class ClearRotation : MonoBehaviour {
void Start ()
{
transform.rotation = Quaternion.identity;
}
}
I just tested again - it seems to work perfectly. Of course, the displayed rotation will only show (0,0,0) if the object has no parent, or its parent’s rotation is Quaternion.identity. This will display (0.0, 0.0, 0.0), though…
The only way I know of to ensure that, is to get its position.x in Start(), and set it to be that in Update(). That seems inefficient, though, so I’d be interested to hear alternative ideas.
Had the same problem. I work in C# but either of these should work.
var newRotation = new Quaternion(); //Default is Quaternion(0,0,0,0)
var newRotation = new Quaternion(0,0,0,0); //Please remember Quaternion have x,y,z, and w.
var newRotation = Quaternion.Eular(0,0,0); //Only if you use Eular are there just x.y.z