# Gizmos misbehave when operating on child objects with configured pivot

**URL:** <https://forum.babylonjs.com/t/gizmos-misbehave-when-operating-on-child-objects-with-configured-pivot/42313>\
**Category:** Bugs\
**Created:** [July 11, 2023, 2:50am UTC](https://forum.babylonjs.com/t/gizmos-misbehave-when-operating-on-child-objects-with-configured-pivot/42313 "2023-07-11T02:50:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![qillerneu](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/qillerneu/32/18517_2.png) [@qillerneu](https://forum.babylonjs.com/u/qillerneu)\
**Post date:** [July 11, 2023, 2:50am UTC](https://forum.babylonjs.com/t/gizmos-misbehave-when-operating-on-child-objects-with-configured-pivot/42313/1 "2023-07-11T02:50:47Z")

</div>

Admittedly, this is an edge case - however the current implementation seems a bit hacky anyway.

The issue:  
We have a complex assembly of objects that are tied into a hierarchy, for example MegaParent → Parent → Box  
If Box has a pivot set for it, using any attached gizmos will cause the object to rapidly fly away:

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

(try using gizmo attached to be Green box)

It looks like that that current implementation using `Gizmo._handlePivot` would handle only some specific cases, but not a hierarchy like in the example.

The core of the problem appears that `Gizmo._matrixChanged` uses `Matrix.decompose` to extract `position` from the local matrix. However, when pivot is set, `TransformNode.computeWorldMatrix` does not use `Matrix.compose` - instead it factors in the pivot matrix. Thus decomposing that local matrix will return a different local position and that error will rapidly accumulate.

A potential fix is to remove the position tweak in `_handlePivot` and handle the “un-compute-world-matrix” better in the `_matrixChanged`:

I’m not **totally** sure that fixes it in all cases thus no PR, but a monkey patch like one around line 100+ here seems to work in our case:

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

---

<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:** [July 11, 2023, 8:33am UTC](https://forum.babylonjs.com/t/gizmos-misbehave-when-operating-on-child-objects-with-configured-pivot/42313/2 "2023-07-11T08:33:21Z")

</div>

cc @Cedric

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [July 11, 2023, 2:56pm UTC](https://forum.babylonjs.com/t/gizmos-misbehave-when-operating-on-child-objects-with-configured-pivot/42313/3 "2023-07-11T14:56:36Z")

</div>

This is something I’ll definitely take a look at. Thanks.

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [July 11, 2023, 2:56pm UTC](https://forum.babylonjs.com/t/gizmos-misbehave-when-operating-on-child-objects-with-configured-pivot/42313/4 "2023-07-11T14:56:41Z")

</div>



---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [September 22, 2023, 8:18am UTC](https://forum.babylonjs.com/t/gizmos-misbehave-when-operating-on-child-objects-with-configured-pivot/42313/5 "2023-09-22T08:18:25Z")

</div>

WIP [Fixes and enhancements for gizmos by CedricGuillemet · Pull Request #14316 · BabylonJS/Babylon.js · GitHub](https://github.com/BabylonJS/Babylon.js/pull/14316)

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [September 22, 2023, 8:18am UTC](https://forum.babylonjs.com/t/gizmos-misbehave-when-operating-on-child-objects-with-configured-pivot/42313/6 "2023-09-22T08:18:39Z")

</div>


