Quaternion no Rotation

Hi,

I’m trying to initiate a new object with Rotation (0,0,0)

For example:

	var newRotation = Quaternion.identity;

But that makes the new object have the same rotation as the parent axis.

I’ve tried:

	var newRotation = (0,0,0);

But I get an error.

How can I give it a rotation of (0,0,0)?

Thanks,
Stuart

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…

Debug.Log(transform.rotation.eulerAngles);

O I C.
I’m a bit confuzzled atm.

I’ll brb after I alter something.

Thanks.

No, that’s assigning a rotation to a transform, not a variable. If you were to do

transform.rotation = newRotation;

after your previous code, however, that would work.

Ah. Thank you. It turns out it was working after all :sweat_smile: .

Another quick question:
Is there any way to lock an objects z axis movement?
e.g Stop and object from moving in a certin axis?

Thanks.

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