Hi @RaananW! I tried reproducing what you advised in the last paragraph (except the animation…I just tried to produce the final orientation), and it was unsuccessful. It seems you illustrated your suggestion in the code you commented out in this playground that you shared: https://www.babylonjs-playground.com/debug.html#4JNT09#20
I attempted to utilize that method to produce a final state of the camera/transformNode, but it did not produce the correct orientation. My attempt can be found here: https://www.babylonjs-playground.com/debug.html#4JNT09#26
Additionally, if using the nesting the camera under a transform node still requires use of camera.setTarget, then I don’t think that is a viable solution, since, as mentioned, setTarget sets the rotation quaternion of the camera based on some pre-assumed vectors/clamping (as also pointed out above). I think the use of the setTarget function is the main issue that is blocking the camera from orienting in the same way as the blender-exported transform node anchors. As can be observed through console logs, the camera’s rotationQuaternion and position can be set to be exactly that of the the camera anchor in global space, and still not yield the proper orientation, I guess due to the overriding of setTarget, which often sets the incorrect rotation about the y axis.
I’m not an expert enough in linear algebra to be confident to make these changes to the setTarget function in Babylon code, but I do think that it could use another look. Very open to be proven wrong
Well, our setTarget code is a few years old (more than 6, actually)! Which can mean one of two things - one it is outdated and should be updated or 2 - it had been used so many times that it is tested and proven.
The core of the issue you are facing is ( I believe) - what is the y rotation when looking straight down towards the ground. if you are exactly above something, perpendicular, what should be the y rotation? well, it all comes down to these lines:
x === 0, meaning z / x is infinity. Math.atan(Infinity) === Math.PI / 2. So, -Math.PI / 2 + Math.PI / 2 is 0! meaning, no rotation around the y axis. What you are saying is - this part - if (vDir.x >= 0.0) should be only > 0 , because this is what you currently need. The best solution for this would be to manually add (or subtract :-)) a little bit of value to X when setting the anchor. This way you guarantee the rotation conversion yourself. We won’t change our setTarget code unless you find a fundamental error in it. It is being used everywhere in the framework and outside of it.
Also notice that you are using right-handed scene, so the calculation is a little different as well.
I believe the entire setup of your scene is forcing you to fight it. you are defining anchors with rotation that require camera position (0,1,0) (and reset rotation) to be applied in order for them to work correctly.
Here is a version with parenting and animation - testing camera anchors | Babylon.js Playground (babylonjs-playground.com)