- Home /
how to use transform.rotation?
i have six variables Xposition, Yposition, Zposition, Xrotation, Yrotation, and Zrotation. i want put this when my player hit a cube (like a checkpoint)
player.transform.position = Vector3(data.Xposition,data.Yposition,data.Zposition);
player.transform.rotation = Vector3(data.Xrotation,data.Yrotation,data.Zrotation);
either this player.transform.position =
player.transform.rotation =Vector3(data.Xposition,data.Yposition,data.Zposition,data.Xrotation,data.Yrotation,data.Zrotation);
but that give me an error. how to solve it?
Answer by Bunny83 · Aug 21, 2012 at 08:01 PM
A Quaternion is a very special way to express a rotation. It uses 4 values (x,y,z,w) which has nothing to do with angle-values. If you want to specify euler angles, you have to use Quaternion.Euler like this:
player.transform.rotation = Quaternion.Euler(data.Xrotation, data.Yrotation, data.Zrotation);
how i can safe the rotation of my player. i can't use data.Yrotation=transform.rotation.y; any solution?
Answer by Panik.Studios · Aug 21, 2012 at 08:51 PM
I had problems with this also the first time I needed to use it.. Bunny is right on.. Here is an example of it being used in a practical application.
function OnLevelWasLoaded(level : int)
{
if (level == 1){
transform.position = Vector3(-30,1.5,0);
transform.rotation = Quaternion (0,90,0,0);
}
}
The 90 rotates my character to the right 90 degrees. Bunny can you explain why Euler Angles are important? I dont get it.. How would that improve the code?
You should really check this out This
It's a great place for learning all the components.. with examples of how to use them.