Child GameObject Rotation with Parent

Hi. I’m trying to get the Child GameObjects of a Parent to rotate relative to the Parent’s Y axis, but they only appear to be rotating on the Global Y axis instead.

I have two private Quaternion values;

LWingExtend = Quaternion.Euler(0.0f, rb.rotation.y + 90.0f, 0.0f);
RWingExtend = Quaternion.Euler(0.0f, rb.rotation.y - 90.0f, 0.0f);

Which become active when a certain parameter is true. The bool is fine and I have this working so that the child objects rotate when this is true, but the issue is on the rotation itself. The Slerps for this are;

FrontWingL.rotation = Quaternion.Slerp(FrontWingL.rotation, LWingExtend, Time.deltaTime);
FrontWingR.rotation = Quaternion.Slerp(FrontWingR.rotation, RWingExtend, Time.deltaTime);

So I’m trying to say, when bool is true, rotate the child gameobject from it’s start rotation to the new quaternion rotation, which works, but it appears to be on the global axis and not the parent axis, so when I rotate the parent further the children just stay in the same rotation. Any help would be awesome!

Use Rigidbody.rotation.eulerAngles.y:

public Rigidbody Rigid;

void Update()
{
    Quaternion.Euler(0.0f, Rigid.rotation.eulerAngles.y + 90.0f, 0.0f);
}

You can also use transform.localRotation.

1 Like

By setting the .rotation property you are specifying the global world rotation

i suspect you want to be setting the .localRotation property of the transform, which is its relative rotation to the parent.

1 Like

Thanks DroidifyDevs. the eulerAngles.y method worked.

I’m going to play around with .localRotation as well, Kurt-Dekker!

Thanks guys! That was a quick fix!

1 Like