Getting Child to Ignore Parent's Rotation?

I have a child attached to parent. The parent rotates, but I need the child to stay at a constant angle. The parent’s rotation varies with time.

Basically, I’d like my child to track the parent’s position only! What’s an elegant way to do this?

-Thanks

1 Like

An idea would be to set the child’s rotation to a fixed angle on every Update. Just put the following code in a script and apply it to the child.

function Update() {
   transform.rotation = Quaternion.identity;
}
3 Likes

Or, have the ‘child’ not really be a child of the parent, but have a script on it that is constantly setting its position = the parents, + some offset vector (in a lateUpdate(), for total syncronization).

1 Like

++

If you only want to track position, it’s easier to just track position with your own script rather than trying to undo rotation (and possibly scale) from a parent.

3 Likes

I sort of did this with a shadow projector, but it was a simpler situation - I wanted it only to rotate around the Global Y with it’s parent (didn’t want it projecting the shadow at crazy angles as the aircraft banked).

So I basically set the projector’s transform.rotation each update for x z to zero and left Y alone…have to look up the code later when I get home.

Good suggestions guys. The problem gets a bit more complicated because consider this application:

A helicopter is composed of a body and the top rotor blades. The blades are set as a child of the helicopter game object and given a fixed rotation. But, when the helicopter parent object itself rotates, the rotor blades’ speed changes in a weird way.

Would you make the rotate blades an entirely separate object and update it’s x,y,z via Update()? That seems unwieldy, no?

Is there a difference in performance if I update the position manually – through Update() – versus parenting?

Or, have the ‘child’ not really be a child of the parent, but have a script on it that is constantly setting its position = the parents, + some offset vector (in a lateUpdate(), for total syncronization).

Can somebody please put this in script form?

2 Likes

Pff , i was doing everything perfectly right but i had forgotten the LateUpdate -_- and i had Update instead fk me :slight_smile:

1 Like

The way I did it was:

Quaternion spawnRot = Quaternion.Euler(90f, 0f, 0f); //setting the rotation of the object to what it originally is
void LateUpdate()
{
transform.rotation = spawnRot; //transforming the rotation each update to that rotation
}

1 Like