Align head mesh with camera rotation


I’ve been trying to put together a human head model that will look where the camera is pointing, and I seem to have come very close without having to pay any attention to the most confusing rotation stuff (quaternions and Euler angles seem way beyond my comprehension) but it’s still just a little off and I can’t figure out what’s missing. There are only 3 lines in the PG that relate to this problem (which I’ve highlighted), and I think it’s just the one in the mainLoop that needs to change. Does anybody know how?

funny little thing :smile:

Here ya go;
I positioned the bridge and eyes properly,
used scene onBeforeRenderObservable ( renderloop is for calling scene.render() the Playground website does it behind the scene :wink: )

First we calculate the direction vector3, from camera position to camera target and normalize it (x + y + z === 1)


We can then convert this direction to the rotations we need for the head

head.rotation.y = -Math.atan2(direction.z, direction.x);
head.rotation.z = Math.asin(direction.y);

:exploding_head::exploding_head::exploding_head: Perfect!! Thanks very much :smiley: