# Physics body on different position with mesh

**URL:** <https://forum.babylonjs.com/t/physics-body-on-different-position-with-mesh/50592>\
**Category:** Bugs\
**Tags:** physics, havok\
**Created:** [May 16, 2024, 5:48am UTC](https://forum.babylonjs.com/t/physics-body-on-different-position-with-mesh/50592 "2024-05-16T05:48:26Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![kzhsw](https://avatars.discourse-cdn.com/v4/letter/k/848f3c/32.png) [@kzhsw](https://forum.babylonjs.com/u/kzhsw)\
**Post date:** [May 16, 2024, 5:48am UTC](https://forum.babylonjs.com/t/physics-body-on-different-position-with-mesh/50592/1 "2024-05-16T05:48:26Z")

</div>

Version: 7.6.2  
Playground:

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

Desc:  
using this code to create physics body of mesh, but resulting physics body is on different position with source mesh, not that not all `PhysicsShapeType`s testes, but the same happens with `BABYLON.PhysicsShapeType.MESH`

```js
var b = new BABYLON.PhysicsAggregate(model, BABYLON.PhysicsShapeType.CONVEX_HULL, {
    mass: 1,
});

```

Step to reproduce:

1. Open the playground
2. Open Inspector
3. Check Debug → HELPERS → Physics

Screenshot:

 ![Screenshot](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/2/1/210c65fcd78b98b35c5ed0ba95c8942e111c74a6.png)

---

<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:** [May 16, 2024, 9:25am UTC](https://forum.babylonjs.com/t/physics-body-on-different-position-with-mesh/50592/2 "2024-05-16T09:25:14Z")

</div>

Hi @kzhsw  
Is it the correct PG?  
I don’t see any reference to convex hull and mesh is different.

---

<div class="post-metadata">

**Author:** ![kzhsw](https://avatars.discourse-cdn.com/v4/letter/k/848f3c/32.png) [@kzhsw](https://forum.babylonjs.com/u/kzhsw)\
**Post date:** [May 18, 2024, 7:39am UTC](https://forum.babylonjs.com/t/physics-body-on-different-position-with-mesh/50592/3 "2024-05-18T07:39:56Z")

</div>

Sorry for the mistake, I’ve updated the main thread and corrected link to the playground

---

<div class="post-metadata">

**Author:** ![Joe\_Kerr](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/joe_kerr/32/39017_2.png) [@Joe\_Kerr](https://forum.babylonjs.com/u/Joe_Kerr)\
**Post date:** [May 18, 2024, 8:11am UTC](https://forum.babylonjs.com/t/physics-body-on-different-position-with-mesh/50592/4 "2024-05-18T08:11:55Z")

</div>

I think it is the same problem as [here](https://forum.babylonjs.com/t/issue-with-trigger-setup-for-glb-model/50610/9).

Baking may be a solution: [https://playground.babylonjs.com/#112FXI#17](https://playground.babylonjs.com/#112FXI#17)

---

<div class="post-metadata">

**Author:** ![kzhsw](https://avatars.discourse-cdn.com/v4/letter/k/848f3c/32.png) [@kzhsw](https://forum.babylonjs.com/u/kzhsw)\
**Post date:** [May 21, 2024, 9:35am UTC](https://forum.babylonjs.com/t/physics-body-on-different-position-with-mesh/50592/5 "2024-05-21T09:35:07Z")

</div>

Hi @Cedric , I’ve updated the link to pg in the main thread, any new ideas?

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

---

<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:** [May 21, 2024, 12:54pm UTC](https://forum.babylonjs.com/t/physics-body-on-different-position-with-mesh/50592/6 "2024-05-21T12:54:48Z")

</div>

I think it’s related to [Incorrect size of physics body - #3 by sebavan](https://forum.babylonjs.com/t/incorrect-size-of-physics-body/50677/3) I’ll check both issues at the same time, later this week.

---

<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:** [May 21, 2024, 12:54pm UTC](https://forum.babylonjs.com/t/physics-body-on-different-position-with-mesh/50592/7 "2024-05-21T12:54:53Z")

</div>

Assigned @Cedric on May 21, 2024, 12:54pm UTC



---

<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:** [May 24, 2024, 8:45am UTC](https://forum.babylonjs.com/t/physics-body-on-different-position-with-mesh/50592/8 "2024-05-24T08:45:31Z")

</div>

The mesh that is used for computing the convex hull has a negative X scaling value. It’s not possible to decompose the scaling in order to transform the positions.  
Fix is to modify the asset and set positive values for all scaling components.

---

<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:** [May 24, 2024, 8:45am UTC](https://forum.babylonjs.com/t/physics-body-on-different-position-with-mesh/50592/9 "2024-05-24T08:45:35Z")

</div>

Unassigned @Cedric on May 24, 2024, 8:45am UTC



---

<div class="post-metadata">

**Author:** ![kzhsw](https://avatars.discourse-cdn.com/v4/letter/k/848f3c/32.png) [@kzhsw](https://forum.babylonjs.com/u/kzhsw)\
**Post date:** [May 25, 2024, 12:07am UTC](https://forum.babylonjs.com/t/physics-body-on-different-position-with-mesh/50592/10 "2024-05-25T00:07:41Z")

</div>

What about `MESH`? The same thing happens with `PhysicsShapeType.MESH`

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

 ![paste](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/f/6/f6ca3127446a6aec66318b3856c770b16785a89c.png)

---

<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:** [May 25, 2024, 12:26am UTC](https://forum.babylonjs.com/t/physics-body-on-different-position-with-mesh/50592/11 "2024-05-25T00:26:43Z")

</div>

Assigned @Cedric on May 25, 2024, 12:26am UTC



---

<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:** [May 27, 2024, 8:31am UTC](https://forum.babylonjs.com/t/physics-body-on-different-position-with-mesh/50592/12 "2024-05-27T08:31:53Z")

</div>

It’s the same internal pipeline with same constraints.

---

<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:** [May 27, 2024, 8:31am UTC](https://forum.babylonjs.com/t/physics-body-on-different-position-with-mesh/50592/13 "2024-05-27T08:31:56Z")

</div>

Unassigned @Cedric on May 27, 2024, 8:31am UTC



---

<div class="post-metadata">

**Author:** ![kzhsw](https://avatars.discourse-cdn.com/v4/letter/k/848f3c/32.png) [@kzhsw](https://forum.babylonjs.com/u/kzhsw)\
**Post date:** [May 27, 2024, 9:54am UTC](https://forum.babylonjs.com/t/physics-body-on-different-position-with-mesh/50592/14 "2024-05-27T09:54:42Z")

</div>

Physics engines should be able to handle all types of meshes, it’s unacceptable to modify the asset everytime

---

<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:** [May 27, 2024, 11:32am UTC](https://forum.babylonjs.com/t/physics-body-on-different-position-with-mesh/50592/15 "2024-05-27T11:32:35Z")

</div>

Using words like ‘unacceptable’ will not help.  
Some engines do not support negative scales or non uniform scaling. We are doing our best to allow most types of assets with minimal modification. And don’t forget the engine is open source. If you think the engine should do something, then do it and open a PR!

---

<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:** [May 27, 2024, 4:36pm UTC](https://forum.babylonjs.com/t/physics-body-on-different-position-with-mesh/50592/16 "2024-05-27T16:36:18Z")

</div>

@kzhsw it is all open source if you have a great way of addressing it not requiring the mesh changes ? we ll be glad to help in the review process

---

<div class="post-metadata">

**Author:** ![kzhsw](https://avatars.discourse-cdn.com/v4/letter/k/848f3c/32.png) [@kzhsw](https://forum.babylonjs.com/u/kzhsw)\
**Post date:** [May 28, 2024, 1:17am UTC](https://forum.babylonjs.com/t/physics-body-on-different-position-with-mesh/50592/17 "2024-05-28T01:17:51Z")

</div>

@sebavan @Cedric I’m quite confusing about “open source”, as far as I know, the havok engine in babylon.js is binary only distribution, where users can only use the per-built wasm binary. It’s really hard to find if the issue it within the wasm binary itself, or somewhere in the babylon.js havok plugin. Also, the docs is very few for both using and developing, and I don’t think external developer have the ability to fix this without more info about the internals of the engine.  
Also, for the negative scale thing, every gltf model imported to babylon.js will contain an negative scale by default, how can users fix something like this?

 ![the inspector](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/6/a/6aa7761ef2790dc0f13b8f7b8ad52a713174d0e1.png)  
I started by reading the docs and thinking the havok engine is a full-featured physics engine like what it branded from, and in the docs there is nothing related to the requirement about scaling of mesh or node except for instances.  
If it’s really required to bake the transformation to vertex, or eliminate scaling from transformation, then document it. If it’s not intended, try to fix it. Being not possible to correctly use gltf models with physics would affect a large amount of users since gltf is a very popular format for web platform.  
Sorry for this long post, but really hope for a real fix about this issue.

---

<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:** [May 28, 2024, 8:20am UTC](https://forum.babylonjs.com/t/physics-body-on-different-position-with-mesh/50592/18 "2024-05-28T08:20:14Z")

</div>

Your case is different: there are negative scales in various part of the mesh hiearchy. In addition to rotations. At the end of the transform chain, it’s not possible to determine the resulting scaling when decomposing the world matrix.  
This is not part of Havok but inside Babylon. Havok doesn’t know about gltf at all.  
I’ll add documentation on baking.

---

<div class="post-metadata">

**Author:** ![kzhsw](https://avatars.discourse-cdn.com/v4/letter/k/848f3c/32.png) [@kzhsw](https://forum.babylonjs.com/u/kzhsw)\
**Post date:** [May 28, 2024, 9:10am UTC](https://forum.babylonjs.com/t/physics-body-on-different-position-with-mesh/50592/19 "2024-05-28T09:10:05Z")

</div>

By decomposing the world matrix, does it mean the negative scales will be applied to quaternion instead of scaling? How can it affect the result since decomposing and composing should make almost the same matrix?

---

<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:** [May 28, 2024, 9:19am UTC](https://forum.babylonjs.com/t/physics-body-on-different-position-with-mesh/50592/20 "2024-05-28T09:19:22Z")

</div>

To make it simple: when decomposing scaling, it’s impossible to make the difference between a negative value or a 180deg rotated one.  
Simple example: a vector value of (-1,0,0). is it (0,0,1) with 90deg rotation on Y or (1,0,0) with a scale of -1?  
It’s possible to deduce some cases but not all.  
The composition of all scaling value (absoluteScaling) is always positive and that value is need when initiating Shapes from mesh with a transform hierarchy.  
One solution is to replace local transform/worldmatrix by decomposed values. Keeping translation/orientation/scaling all along the transform hierarchy, everywhere in the engine from the scene graph, to the skeletal animation,… up to the rendering where you can compose a worldmatrix. This means rewriting a LOT. Or you can eliminate negative, non uniform scaling. Other users managed to do it and released production.

[Next page](https://forum.babylonjs.com/t/physics-body-on-different-position-with-mesh/50592.md?page=2)
