I set the camera's target x to 0.1 but when I read it back it’s 0. However the camera points to the correct position.
var camera = new BABYLON.FreeCamera('camera', new BABYLON.Vector3(0, 0, -8), scene, true)
const front = camera.getFrontPosition(1)
front.x = 0.1
camera.target = front
// camera.setTarget(front)
console.log("camera.target", camera.target)
console.log("target vector3", front)
What’s wrong here?
Thank you!
r.
EDIT: it’s working in the PG with BJS 4.1.0 EDIT2: Damned, it is not. The target is correctly read back but the camera position is not set correclty…
Maybe the displayed value is being mis-rounded by your browser or just rounded to the nearest whole number? Here are the results I get from the PG, where the values are equal within a small epsilon…
I am aware of the rounding issue. I was once debugging something where a simple comparison was not working despite I saw the same values in the console for hours
x set to 100:
I came across this issue while I tried to increment the target.x in a before render observable and it didn’t work. So there must be something else. And as I wrote, in 4.1.0 it writes out the right values. Pretty interesting
EDIT: OK I tried it on v4 too now and it seems to be working the same as v5, the target is visibly changed and the values displayed in the console are the same for me as well…
Hmm, maybe the browser is showing you an outdated cached version of the object?
Another thing here is that why am I getting different camera views with these camera setups?
Shouldn’t it be the same?
const camera = new BABYLON.ArcRotateCamera(
'camera',
BABYLON.Tools.ToRadians(90),
BABYLON.Tools.ToRadians(20),
10,
new BABYLON.Vector3(0, 80, 0), // target
scene
)
const camera = new BABYLON.ArcRotateCamera(
'camera',
BABYLON.Tools.ToRadians(90),
BABYLON.Tools.ToRadians(20),
10,
new BABYLON.Vector3(),
scene
)
camera.target = new BABYLON.Vector3(0, 80, 0) // same target
There is something wrong with the target property.
The constructor sets alpha, beta and radius after calling setTarget(), if you do the same thing then the result is the same, like below. In the above 2nd example the target was being set after these instead of before so the result was different, it seems.
So I was able to repro on windows and calling camera.updateWorldMatrix() seems to fix the issue in the PG repro, although IDK why it’s only needed on windows and it doesn’t seem to help us to be able to animate the target…
Thank you for assuring me that I was not completely off I discovered it after a 20 hours long coding session, working on 3 projects at a time, skipping from one to another and I was not sure even of the reality vs matrix question at the end