# Camera target "lost"

**URL:** <https://forum.babylonjs.com/t/camera-target-lost/27286>\
**Category:** Bugs\
**Created:** [February 1, 2022, 4:52pm UTC](https://forum.babylonjs.com/t/camera-target-lost/27286 "2022-02-01T16:52:40Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![roland](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/roland/32/38940_2.png) [@roland](https://forum.babylonjs.com/u/roland)\
**Post date:** [February 1, 2022, 4:52pm UTC](https://forum.babylonjs.com/t/camera-target-lost/27286/1 "2022-02-01T16:52:40Z")

</div>

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.

```auto
    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)

```

> **[Babylon.js Playground](https://playground.babylonjs.com/#VGHWDV%231)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/9/0/90b0a09d188bcf914cc991fac4089614f1267a66.png)

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…

---

<div class="post-metadata">

**Author:** ![Blake](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/blake/32/21509_2.png) [@Blake](https://forum.babylonjs.com/u/Blake)\
**Post date:** [February 1, 2022, 7:23pm UTC](https://forum.babylonjs.com/t/camera-target-lost/27286/2 "2022-02-01T19:23:42Z")

</div>

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…

 ![screenshot](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/b/c/bc76242b6c6ec744f47a253c9915833b9333cdb5.png)

---

<div class="post-metadata">

**Author:** ![roland](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/roland/32/38940_2.png) [@roland](https://forum.babylonjs.com/u/roland)\
**Post date:** [February 1, 2022, 7:45pm UTC](https://forum.babylonjs.com/t/camera-target-lost/27286/3 "2022-02-01T19:45:24Z")

</div>

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 😃

`x` set to 100:  
 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/9/5/9527a25bba5cc8f9c43fb65fe3025bd7dc317de4.png)

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 👻

---

<div class="post-metadata">

**Author:** ![Blake](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/blake/32/21509_2.png) [@Blake](https://forum.babylonjs.com/u/Blake)\
**Post date:** [February 1, 2022, 7:50pm UTC](https://forum.babylonjs.com/t/camera-target-lost/27286/4 "2022-02-01T19:50:46Z")

</div>

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

 ![screenshot 2](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/5/7/57015f1b2a571828fe373312c0dcad87562490ca.png)

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?

---

<div class="post-metadata">

**Author:** ![roland](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/roland/32/38940_2.png) [@roland](https://forum.babylonjs.com/u/roland)\
**Post date:** [February 1, 2022, 8:03pm UTC](https://forum.babylonjs.com/t/camera-target-lost/27286/5 "2022-02-01T20:03:07Z")

</div>

Going to try another browser 🙊

---

<div class="post-metadata">

**Author:** ![roland](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/roland/32/38940_2.png) [@roland](https://forum.babylonjs.com/u/roland)\
**Post date:** [February 1, 2022, 8:25pm UTC](https://forum.babylonjs.com/t/camera-target-lost/27286/6 "2022-02-01T20:25:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![roland](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/roland/32/38940_2.png) [@roland](https://forum.babylonjs.com/u/roland)\
**Post date:** [February 1, 2022, 8:30pm UTC](https://forum.babylonjs.com/t/camera-target-lost/27286/7 "2022-02-01T20:30:43Z")

</div>

But only on Mac ofcourse 😛

---

<div class="post-metadata">

**Author:** ![roland](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/roland/32/38940_2.png) [@roland](https://forum.babylonjs.com/u/roland)\
**Post date:** [February 1, 2022, 8:59pm UTC](https://forum.babylonjs.com/t/camera-target-lost/27286/8 "2022-02-01T20:59:42Z")

</div>

Another thing here is that why am I getting different camera views with these camera setups?  
Shouldn’t it be the same?

```auto
  const camera = new BABYLON.ArcRotateCamera(
    'camera',
    BABYLON.Tools.ToRadians(90),
    BABYLON.Tools.ToRadians(20),
    10,
    new BABYLON.Vector3(0, 80, 0), // target
    scene
  )

```

```auto
  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.

---

<div class="post-metadata">

**Author:** ![Blake](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/blake/32/21509_2.png) [@Blake](https://forum.babylonjs.com/u/Blake)\
**Post date:** [February 1, 2022, 9:12pm UTC](https://forum.babylonjs.com/t/camera-target-lost/27286/9 "2022-02-01T21:12:50Z")

</div>

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. 🙂

> **[Babylon.js Playground](https://playground.babylonjs.com/#6ILFEN%231)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![roland](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/roland/32/38940_2.png) [@roland](https://forum.babylonjs.com/u/roland)\
**Post date:** [February 1, 2022, 9:23pm UTC](https://forum.babylonjs.com/t/camera-target-lost/27286/10 "2022-02-01T21:23:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Blake](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/blake/32/21509_2.png) [@Blake](https://forum.babylonjs.com/u/Blake)\
**Post date:** [February 1, 2022, 11:40pm UTC](https://forum.babylonjs.com/t/camera-target-lost/27286/12 "2022-02-01T23:40:33Z")

</div>

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… 🤔

> **[Babylon.js Playground](https://playground.babylonjs.com/#VGHWDV%232)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![roland](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/roland/32/38940_2.png) [@roland](https://forum.babylonjs.com/u/roland)\
**Post date:** [February 2, 2022, 4:09am UTC](https://forum.babylonjs.com/t/camera-target-lost/27286/13 "2022-02-02T04:09:09Z")

</div>

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 😂

🖖

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [February 2, 2022, 2:44pm UTC](https://forum.babylonjs.com/t/camera-target-lost/27286/14 "2022-02-02T14:44:22Z")

</div>

I can not repro on Windows ☹

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/e/a/ea343603343f2cbaac0c92897f646a6de0cfbf82.png)

Is there anything special to do ?

---

<div class="post-metadata">

**Author:** ![roland](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/roland/32/38940_2.png) [@roland](https://forum.babylonjs.com/u/roland)\
**Post date:** [February 2, 2022, 5:01pm UTC](https://forum.babylonjs.com/t/camera-target-lost/27286/15 "2022-02-02T17:01:42Z")

</div>

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

Thanks anyway! 😛
