How to freeze child gameobject rotation???

Hello
I have 2 gameobject the first one is parent and the second is child , if the parent gameobject rotate the child gameobject rotate too, and I want to freeze the child object from rotation…

thx…

3 Answers

3

I didn’t test this, but I believe that you can just set the child transform.rotation to a fixed value in LateUpdate to eliminate any parent-originated rotation. You can save the initial child rotation at Start, like below (attach this to the child):

var iniRot: Quaternion;

function Start(){
    iniRot = transform.rotation;
}

function LateUpdate(){
    transform.rotation = iniRot;
}

NOTE: If the parent is being moved by physics you may have problems, because physics runs at its own pace, and a cycle may occur between LateUpdate and the scene rendering.

thanks for the script !..was having same problem

–

Many thanks to you sir.

–

Gracias, el efecto final es increíble.

–

Liking the simple solution. But what if I want to freeze the X and Z axis only? I get an error when using transform.rotation.y = rotation.y ?

–

this script work . attach with child object … :slight_smile:

    function Update () {
var rotation = Quaternion.LookRotation(Vector3.up , Vector3.forward);
transform.rotation = rotation;
}

But not working if I use "AddForce" to this object

–

Liking the simple solution. But what if I want to freeze the X and Z axis only?
I get an error when using transform.rotation.y = rotation.y ?