Avarage quaternions

hey guys. i have a camera that sits behind the player, and the cameras rotation = player rotation.

i am trying to average this out so that when the player shakes the mouse left and right really fast, the camera doesn’t shake to badly…

i have tried to lerp to the new angle, but this doesn’t give me the result i am looking for. lerping from current to target with a weight of 0.5f should give me the avarage of those 2, but i cant figure out how to do more than two? an x amount of samples?

Use an ArrayList, every frame add a new Quaternion to the end until it reaches the number of Quaternions that you want, after that, remove the first one.

Every frame add all of the rotations together and divide it by the number of items in the list. (If this works I would be amazed because I am not sure Quaternions average like normal numbers.)

Conversely, you could use euler angles instead. Those will average.

You can average quaternions in some cases, but you’ll generally need to normalize the result. (For example, nlerp(q1, q2, .5) essentially averages the two input quaternions.)

They may average, but the results may not always be as expected. For example, average(350, 0) might give you 175, even if the desired result is 355. (You can write code that works around the periodicity issues, but generally it’s easier just to use another representation.)