Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Quaternion Math

Name: Anonymous 2010-10-21 18:44

I'm making a tetris type game as part of my learning process for Unity3D. I'm handling piece rotation by:
-have a variable for desired angle
-the player changes this in steps of 90deg with keypresses
-every frame, rotate 1/10th of the way there.

Code is:
//set a var for the (req)uired angle
  var anglereq : Vector3 = Vector3(0,0,0);
//put the difference between the current angle and the anglereq into a temp
  var temp : Vector3 = anglereq - rigidbody.rotation.eulerAngles;
//add 1/10th of temp to the current angle (as im dealing with Vec3's, need to convert the rigidbody.rotation into eulers,
//add the temp/10, then back into Quats), this new quat goes into newrot
  var newrot : Quaternion = Quaternion.Euler(rigidbody.rotation.eulerAngles + temp/10);
//Set the rotation to newrot
  rigidbody.MoveRotation(newrot);

This works fine, until the angle required goes over 0,0,360, or drops into negatives.

Name: Anonymous 2010-10-22 12:57

it's stupid to think that a rotation can be un-done by rotating back in the same planes but in a different order
Is that really true of quaternions? It's certainly not true in general.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List