- Home /

# fixing rotation on a specific axis

I found this script on a forum for almost what i was looking for:

```
var X_RotationLockedAt : int ; //locking the rotation at a certain angle for X
var Y_RotationLockedAt : int ; //locking the rotation at a certain angle for Y
var Z_RotationLockedAt : int ; //locking the rotation at a certain angle for Z
function FixedUpdate(){
transform.rotation = Quaternion.Euler(X_RotationLockedAt, Y_RotationLockedAt, Z_RotationLockedAt);
}
```

But how do i get it to only freeze on one axis for example freeze on the Y axis but move with the parent object on X and Z, i tried

```
transform.rotation = Quaternion.Euler.Y = Y_RotationLockedAt;
```

But it didn't work... no errors just didn't work!

Thanks in advance!

**Answer** by hirenkacha
·
Jun 25, 2013 at 10:39 AM

Try using this

```
transform.eulerAngles = Vector3(0, Y_RotationLockedAt, 0); //check : Y_RotationLockedAt is in Euler
```

I used for C#

```
transform.eulerAngles = new Vector3(0f,Y_RotationLockedAt,0f);
```

what do you mean by 'check : Y_RotationLockedAt is in Euler?' i've tried transform.eulerAngles = Vector3(X_RotationLockedAt, 0, Z_RotationLockedAt); as i want to freeze it in all but Y, it must be because it's still set to 0 on all 3... how can i make a var = to a Transform variable's Y rotation, so that i could set the Y value to this number var and make the number var be = to the parent's Y rotation (parent = Transform var)

for example:

var Parent : Transform; var ParentYvalue = 0;

ParentYvalue = to the Y rotation (this is what i don't know how to do)

transform.eulerAngles = Vector3(0, ParentYvalue, 0);

so that when the parent moves, it matches the Y yet the others are still 0 so only the Y moves... but how do i make a float variable = to a Transform variable's Y rotation... thanks look forward to your reply

You can have y rotation in eulers of a parent using this

`ParentYvalue = Parent.eulerAngles.y;`

then use that in the object which you want to rotate.

```
transform.eulerAngles = Vector3(0, ParentYvalue , 0);
```

### Your answer

### Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.