I have an object with a rotation being driven by a gyro, and I need the ability to recenter it. I haven’t been able to figure out a way to reset the gyro so instead I’ve been trying to rotate a parent of that object to be the opposite rotation, such that if the child is rotated 90 degrees in the x, the parent will get rotated -90 degrees in the x, thus making it seem as though the child is facing the origin again. I can’t quite seem to get this to math out though. Should I be doing something else?

I’ve tried the following methods but nothing seems to work quite the way i want it to.

parent.localEulerAngles = new Vector3(
            -child.localEulerAngles.x,
            -child.localEulerAngles.y,
            -child.localEulerAngles.z);

parent.localEulerAngles = new Vector3(
            360f-child.localEulerAngles.x,
            360f-child.localEulerAngles.y,
            360f-child.localEulerAngles.z);

parent.localRotation = Quaternion.Inverse(child.localRotation);

parent.localRotation= Quaternion.LerpUnclamped(child.localRotation, Quaternion.Identity, 2f);

Anyone have any thoughts on what else I should try to get this thing recentered?

Here is what I use

Quaternion qBase = Quaternion.identity;

    //to recenter call
    qBase =  Quaternion.Inverse(Gyro.quat);


    //updating my current quaternion
    transform.localRotation = qBase * Gyro.quat;

You’ll want to filter the gyro data and all but that’s probably what you need to “recenter” :slight_smile:

Well ultimately i got it working by deleting the child prefab and re instantiating it which is something i was hoping to avoid having to do but will work for now. using Quaternion.Inverse() as JC_SummitTech suggested above seems to work the first time but after that it gets wonky. This probably means that there is a problem deeper in the code elsewhere. I’ll update this answer if I can figure out what that is.