- Home /
Doing 2D only rotation using FromToRotation + RotateTowards
Hi,
I am currently doing a 2D only rotation -- in the X-Y plane only. I want to the object's geometry to face a certain direction. By default, the facing direction for the geometry is always (0, 1, 0), so I do the following:
// rotate toward proper orientation
Vector3 fromVec = new Vector3(0.0f, 1.0f, 0.0f),
// desired orientation
orientation = new Vector3(orientationVec[0], orientationVec[1], 0.0f);
// create quaternion representing rotation fromVec to orientation
Quaternion toQuat = Quaternion.FromToRotation(fromVec, orientation);
// affect geometry's local rotation
geomTransform.localRotation = Quaternion.RotateTowards(geomTransform.localRotation, toQuat, sOrientationSpeed*timeItr);
It seems to work fine for the most part. It looks like that it would only do a 2D rotation based on the vectors used (z components = 0), but you never know.
Now I was wondering if it was possible for the object to "flip" around to face the orientation vector so that its backside is showing? i.e. it's supposed to rotate inside of (x-y) the plane but it could rotate around it (i.e. with respect to Z). I think that this may have happened before but it's difficult to reproduce. It's currently a flat planar object that is parallel with the X-Y plane...so if that happens, I would notice it.
Thanks...