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 16:39

>>15
Turn an object 90 degrees in the XY plane.  Then turn it 90 degrees in the XZ plane.  Now try to turn it back by turning it first in the XY plane, and then in the XZ plane.  It's not possible.

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