I found a weird behavior when setting the camera rotation property.
This is reproducible in the playground, I have prepared a few scenarios:
(is setting camera.Rotation even the correct way to rotate the UniversalCamera?)
Full playground:
https://playground.babylonjs.com/#F68Z6N
preamble
var scene = new BABYLON.Scene(engine);
var camera = new BABYLON.UniversalCamera("camera1", new BABYLON.Vector3(0, 20, 0), scene);
camera.setTarget(BABYLON.Vector3.Zero());
camera.attachControl(canvas, true);
var light = new BABYLON.HemisphericLight("light", new BABYLON.Vector3(0, 1, 0), scene);
light.intensity = 0.7;
var sphere = BABYLON.MeshBuilder.CreateSphere("sphere", {diameter: 2, segments: 32}, scene);
sphere.position.y = 1;
sphere.position.x = 3;
var ground = BABYLON.MeshBuilder.CreateGround("ground", {width: 5, height: 10}, scene);
Scenario A: default
Scenario B:
camera.rotation = new BABYLON.Vector3(Math.PI / 2, 0, 0);
Scenario C:
camera.rotation = new BABYLON.Vector3(Math.PI / 2, 0, Math.PI);
Scenario D:
camera.rotation = new BABYLON.Vector3(Math.PI / 2, 0, 0.001);
Scenario E:
camera.rotation = new BABYLON.Vector3(Math.PI / 2, 0, 0.001);
scene.render()
camera.rotation = new BABYLON.Vector3(Math.PI / 2, 0, 0);
This does not just affect the Z-Axis:
Scenario F
camera.rotation = new BABYLON.Vector3(Math.PI / 2, 1, 0);
Scenario G
camera.rotation = new BABYLON.Vector3(Math.PI / 2, 0, 1);
scene.render()
camera.rotation = new BABYLON.Vector3(Math.PI / 2, 1, 0);
Note: just calling scene.render beforehand is not enough, you actually need to set it to a different value, then render, then change the value again.
Now, I haven’t though too long about what the correct behavior actually should be, but the fact alone that B and E (or F and G) are different should show that something is wrong.