Hello, I am creating a VR game where the player's motion controllers control their hands. Unlike most VR games, the in-game hands do not follow the virtual hands 1:1, but instead interpolate their position/orientation towards the motion controllers' tracked position/orientations.
(This is the game for context
—the interpolation allows the very large giant to interact with the player without moving silly fast).
I am using Unity engine and their implementation of Quaternion.Slerp to interpolate the hand rotation towards the goal. This works very well, but an issue happens if the VR player rotates their wrist very quickly. Because Slerp takes the shortest path to the target orientation, if the player manages to rotate their wrist a full 180 degrees before the hand can catch up, the shortest path will now be in the opposite direction and the hand will reverse its rotation direction accordingly. Below is an animation of this occurring in slow motion. The axis markers denote the hand's current orientation and the goal orientation.
![](https://uploads.gamedev.net/forums/monthly_2020_01/2d8ba45c44604d279d83a8dd74b104e5.HandFlip.gif)
I would prefer instead that if the rotation direction has changed, I can determine if a “flip” is going to occur and instead continue along the current direction (which is now no longer the shortest path—Unity can do this with passing a negative value into SlerpUnclamped).
![](https://uploads.gamedev.net/forums/monthly_2020_01/2a5a22beea544b228cc287902efba31b.image.png)
I'm not sure how to determine if a direction change has occurred (or if this is possible), since quaternions live in 3D space (and not 2D like the above diagram. I looked into using the sign of the dot product to compare orientations between frames, since it looks like it passes from positive to negative when 180 degrees are passed, but I've also been able to get that positive→negative transition to occur without passing 180, so I don't entirely know what its properties are.
Intuitively it is easy to see when a flip occurs, but I'm not sure how to figure it out in code, or if quaternions have any properties than can help.
Thanks for any help,
Erik