Rotating Child Object Independently Without It Being Affected By Parent?

Is it possible to make a child object rotate independently of the parents rotation and keep the parents position?

In my scene the parent/player, with a rigidbody on it, has a mouselook script that allows me to see wherever I point the mouse. When the player hits a “gift box” a spinning wheel, that is actually a child object, is enabled/activated and starts rotating on the Y-axis using add force and it’s own rigidbody.

But when I look around while the wheel spins, it gets all messed up and spins in every-which direction. No constrains have worked to solve the problem. I have found 0 solutions in the forums. HEELP!!!

I can’t simply instantiate the wheel and not have it as a child object, because it is part of a much larger coordinated set of functions and objects that are instantiated when the level is loaded (multiplayer game). But there must be a solution to this frustrating issue. I would greatly appreciate the help.

It’s such a small thing: Make a 3D object wheel spin and stay in front of the camera as though it was a GUI, and stay in place regardless of the mouselook script…Can anybody help me fix this?

If you can’t have your wheel out of player hierarchy, then you need to compensate parent’s rotation. In late update, after all animations and effects and controls applied, set the wheel global rotation to desired value to override parent rotation:

private void LateUpdate(){
    wheel.transform.rotation = Quaternion.euler(Mathf.Sin(Mathf.Deg2Rad * Time.time), 0, 0);
}
1 Like

Thank you so much for your reply. I tried applying the code to the camera that has the mouselook script on it and then add public GameObject wheel; But it seems to override the rotation force on the wheel and turn it on it’s side. I tried Mathf.Sin(Mathf.Deg2Rad * Time.time on all axis and it didn’t work, but I’m sure the counteracting principle is the key.

I should’ve posted my mouselook code. Here it is:

rotationX += Input.GetAxis("Mouse X") * lookSpeed;
        rotationY += Input.GetAxis("Mouse Y") * lookSpeed;

        transform.localRotation = Quaternion.AngleAxis(rotationX, Vector3.up);
        transform.localRotation *= Quaternion.AngleAxis(rotationY, Vector3.left);

This is what needs to be counter acted. I hope the wheel rotation:

    Vector3 torque;
        torque.y = Random.Range(-200, 200);
        //gO.AddRelativeTorque(0f, 2000f, 0f, ForceMode.Impulse);
        gO.AddTorque(Vector3.left * torque.y, ForceMode.Impulse);

-will still work.

Do you how to implement the counter rotation when its input.GetAxis and transform local rotation that is used as mouselook by any chance? I’m so stuck :confused: