# Rotating an object in position

i have been trying to build Tetris, and i have almost everything worked out but i cannot get the piece to rotate in position; whenever i tried to rotate it, it rotated as if around another object… i don’t understand why this is happening. could it be because my object is a prefab made out of multiple objects? here is the code for the movement of the blocks(i have not added the downward momentum yet).

``````#pragma strict

public var falling : boolean;

function Start()
{
falling = true;
}

function Update()
{
if(this.falling == true)
{
if(Input.GetKeyDown(KeyCode.LeftArrow))
{
this.transform.position.x -= 1;
}

if(Input.GetKeyDown(KeyCode.RightArrow))
{
this.transform.position.x += 1;
}

if(Input.GetKeyDown(KeyCode.UpArrow))
{
this.transform.rotation.z += 90;
}

if(Input.GetKeyDown(KeyCode.DownArrow))
{
this.transform.position.y -= 1;
}
}
}
``````

You might be used to rotation that’s measured by “Euler angles” (degrees of rotation around the X, Y, and Z axes). Unity can support that, but doesn’t use it internally.

Unity uses quaternions to represent rotation. They’re a more difficult mathematical concept, but make it easier to interpolate rotations, and avoid gimbal lock (difficulty rotating at extreme positions).

Quaternions do have values named `x`, `y`, and `z` (plus a `w`), but they don’t do what you’re expecting.

So, let’s suppose you want a quaternion rotated 90 degrees around the z-axis:

``````Quaternion rot = Quaternion.Euler(0, 0, 90);
``````

Then, we apply this rotation:

``````Quaternion rot = Quaternion.Euler(0, 0, 90);
transform.rotation *= rot;
``````

As a shortcut, you can call the transform’s Rotate function:

``````transform.Rotate(0, 0, 90);
``````

if(Input.GetKeyDown(KeyCode.UpArrow))
{
this.transform.rotation.eularAngles.z += 90;
}
//Try this