Improbable Icon


Converting Between Quaternions`


I didn’t easily find another question about this on the forums (i would have expected to), but what is considered the best way to convert between an Improbable.Core.Quaternion and a UnityEngine.Quaternion?

The way im doing it is:

does this seem sane?




Hey @AnTennA,

Yep, this looks correct to me! I’d personally recommend separating it out into a static Util class so you can easily call methods like ToUnityQuaternion/ToNativeQuaternion.

public static UnityEngine.Quaternion ToUnityQuaternion(Improbable.Core.Quaternion quaternion)
    return new UnityEngine.Quaternion(quaternion.x, quaternion.y, quaternion.z, quaternion.w);

public static Improbable.Core.Quaternion ToNativeQuaternion(UnityEngine.Quaternion quaternion)
    return new Improbable.Core.Quaternion(quaternion.x, quaternion.y, quaternion.z, quaternion.w);

Let me know if this works for you!



@claire – thank you! any reason why you’d recommend a method like these as opposed to an extension method??


Hey! Apologies for not getting back to you sooner.

My reply didn’t use extension methods, but that doesn’t mean you shouldn’t! :slight_smile: I missed that you’d made it within a SpatialQuaternionExtensions class, so I think implementing these as extension methods is fine. It’ll keep your code more readable than constantly calling MyHelperClass.ToUnityQuaternion(blah) everywhere :smiley: