# TargetCamera rotationQuaternion bug

**URL:** <https://forum.babylonjs.com/t/targetcamera-rotationquaternion-bug/39422>\
**Category:** Bugs\
**Created:** [March 28, 2023, 8:13pm UTC](https://forum.babylonjs.com/t/targetcamera-rotationquaternion-bug/39422 "2023-03-28T20:13:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ephillips](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ephillips/32/29099_2.png) [@ephillips](https://forum.babylonjs.com/u/ephillips)\
**Post date:** [March 28, 2023, 8:13pm UTC](https://forum.babylonjs.com/t/targetcamera-rotationquaternion-bug/39422/1 "2023-03-28T20:13:06Z")

</div>

There appears to be a bug where setting the “rotationQuaternion” of a target camera will not cause the view matrix to be updated for very specific quaternion values. See the linked playground to demonstrate the bug: [https://playground.babylonjs.com/#WH5VU0#2](https://playground.babylonjs.com/#WH5VU0#2)

The source of this issue looks to be the following lines of code in the TargetCamera class where it only updates the “UpVector” if the Z component of either the rotationQuaternion or the rotation vector has changed. This is not a safe optimization though since the up vector is only the same if only the y component changes, so therefore checking for only a change in the Z component is insufficient to determine that the up vector is still unchanged (see my comments on the affected lines).

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

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [March 29, 2023, 9:33am UTC](https://forum.babylonjs.com/t/targetcamera-rotationquaternion-bug/39422/2 "2023-03-29T09:33:02Z")

</div>

cc @PolygonalSun

---

<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:** [March 29, 2023, 8:54pm UTC](https://forum.babylonjs.com/t/targetcamera-rotationquaternion-bug/39422/3 "2023-03-29T20:54:30Z")

</div>

Assigned @PolygonalSun on March 29, 2023, 8:54pm UTC



---

<div class="post-metadata">

**Author:** ![PolygonalSun](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/polygonalsun/32/2704_2.png) [@PolygonalSun](https://forum.babylonjs.com/u/PolygonalSun)\
**Post date:** [March 30, 2023, 9:27pm UTC](https://forum.babylonjs.com/t/targetcamera-rotationquaternion-bug/39422/4 "2023-03-30T21:27:08Z")

</div>

I don’t see any reason why it shouldn’t rotate if z = 0 and x != 0 but lemme check with the team first to see why this check was set up this way.

---

<div class="post-metadata">

**Author:** ![PolygonalSun](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/polygonalsun/32/2704_2.png) [@PolygonalSun](https://forum.babylonjs.com/u/PolygonalSun)\
**Post date:** [April 5, 2023, 10:00pm UTC](https://forum.babylonjs.com/t/targetcamera-rotationquaternion-bug/39422/5 "2023-04-05T22:00:04Z")

</div>

Just wanted to update that I have a PR out to address this: [TargetCamera: Check for changes on all axes when handling rotations by PolygonalSun · Pull Request #13700 · BabylonJS/Babylon.js (github.com)](https://github.com/BabylonJS/Babylon.js/pull/13700)
