I would generally do the animation and associate the frame ratio with the rotation of the camera. Accordingly, the client transmitted the keys to the animation.
Animation is simpler, you can also customize other bones, for realism. For example, bending the back.
But I am far behind you, my character can not walk yet
Well, you are right, at a certain (rotation) angle I could let the back rotate for- and backwards instead of rotating the head even more.
However, this small check: if (!oldViewDir.equals(viewDirection)) is not that ābadā in my opinion. Itās easy to understand and at least a little optimized.
So the head is not a child of the model? Else itās difficult to see how a world-space view direction can properly set the angles for the child if the parent happens to be rotated.
Also āunnecessary complicatedā is one call to worldToLocal().
Vector3f localViewDir = model.worldToLocal(viewDir.add(model.getWorldTranslation()), null);