Camera target "lost"

Hi!

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)

image

What’s wrong here? :melting_face:

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…

Hey @Blake!
Thanks for the response!

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 :smiley:

x set to 100:
image

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 :ghost:

1 Like

Here’s what I get after setting it to 100 instead of 0.1, still accurate within a small epsilon.

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?

1 Like

Going to try another browser :speak_no_evil:

1 Like

So it’s 0 in Edge, FF, Chrome on Windows
But it’s 0.99999999 on Mac/Brave (Chromium based) so basically it’s ok.

1 Like

But only on Mac ofcourse :stuck_out_tongue:

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. :slight_smile:

1 Like

Yes, it makes sense, however the issue with target property is still there on Windows.
And I think I should have a break :smiley:
Thank you @Blake !

2 Likes

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… :thinking:

2 Likes

Thank you for assuring me that I was not completely off :joy::joy::joy: 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 :joy:

:vulcan_salute:

1 Like

I can not repro on Windows :frowning:

Is there anything special to do ?

This was fixed by someone in the build from yesterday :smiley: :smiley:
It’s working for me too now…

Thanks anyway! :stuck_out_tongue:

1 Like