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.
-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.