# Bounding box does not compute correctly

**URL:** <https://forum.babylonjs.com/t/bounding-box-does-not-compute-correctly/38448>\
**Category:** Questions\
**Created:** [February 23, 2023, 5:10am UTC](https://forum.babylonjs.com/t/bounding-box-does-not-compute-correctly/38448 "2023-02-23T05:10:06Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![phaselock](https://avatars.discourse-cdn.com/v4/letter/p/da6949/32.png) [@phaselock](https://forum.babylonjs.com/u/phaselock)\
**Post date:** [February 23, 2023, 5:10am UTC](https://forum.babylonjs.com/t/bounding-box-does-not-compute-correctly/38448/1 "2023-02-23T05:10:06Z")

</div>

I was gonna prep a trailer for v6 but then noticed this, so I threw a trailer out the window…

repro: [Babylon.js Playground](https://playground.babylonjs.com/#M3A71T)

There are 3 ways to fix the correct bounding box.  
a) comment out `sphere.attachToBone(sk.bones[sk.getBoneIndexByName("Bone.001")], body);`  
b) or comment out `anim.goToFrame(anim.toFrame);`  
c) or change the PG version to 4.2.1 😃

I did a quick scour of the changelog and didn’t see any breaking announcement related to it. But a ton of work was done to animations… so wai ? or bug ?

---

<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:** [February 23, 2023, 8:38am UTC](https://forum.babylonjs.com/t/bounding-box-does-not-compute-correctly/38448/2 "2023-02-23T08:38:07Z")

</div>

Maybe @bghgary knows something about this ?

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [February 23, 2023, 1:33pm UTC](https://forum.babylonjs.com/t/bounding-box-does-not-compute-correctly/38448/3 "2023-02-23T13:33:27Z")

</div>

Sorry, I don’t see the difference between the current and 4.2.1 version? In both cases the sphere is being pushed to outside the cube right?

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [February 23, 2023, 5:54pm UTC](https://forum.babylonjs.com/t/bounding-box-does-not-compute-correctly/38448/4 "2023-02-23T17:54:20Z")

</div>

I think we are talking about the bounding box. In 4.2.1, the bounding box matches the box. In latest, it does not.

4.2.1:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/7/b/7ba96f1f07e01f2c4ac5e76d66f59144c629f0d8.png)

Latest:

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

It seems to be intermittent though. Sometime latest will show the correct bounding box.

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [February 23, 2023, 6:05pm UTC](https://forum.babylonjs.com/t/bounding-box-does-not-compute-correctly/38448/5 "2023-02-23T18:05:27Z")

</div>

It looks like the bounding box center is different sometimes. When it works, it’s (0, 1, 0) but sometimes it will be computed as (0, 0, 0) which creates the offset.

If I put a `setTimeout`, it seems to always work: [https://playground.babylonjs.com/#M3A71T#3](https://playground.babylonjs.com/#M3A71T#3)

Did we change the way animationEnd works between 4.2.1 and latest?

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [February 23, 2023, 6:19pm UTC](https://forum.babylonjs.com/t/bounding-box-does-not-compute-correctly/38448/6 "2023-02-23T18:19:20Z")

</div>



---

<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 24, 2023, 2:23am UTC](https://forum.babylonjs.com/t/bounding-box-does-not-compute-correctly/38448/7 "2023-02-24T02:23:42Z")

</div>



---

<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 24, 2023, 2:23am UTC](https://forum.babylonjs.com/t/bounding-box-does-not-compute-correctly/38448/8 "2023-02-24T02:23:50Z")

</div>

Will be fixed by [Fix Skeleton Bounding Box Timing issue by sebavan · Pull Request #13561 · BabylonJS/Babylon.js · GitHub](https://github.com/BabylonJS/Babylon.js/pull/13561)

---

<div class="post-metadata">

**Author:** ![phaselock](https://avatars.discourse-cdn.com/v4/letter/p/da6949/32.png) [@phaselock](https://forum.babylonjs.com/u/phaselock)\
**Post date:** [March 11, 2023, 1:41am UTC](https://forum.babylonjs.com/t/bounding-box-does-not-compute-correctly/38448/9 "2023-03-11T01:41:46Z")

</div>

Tested, fix works. Marking as solved, thanks!
