Browse Source

updateBodyPosition updated with parent constraints

Temechon 11 years ago
parent
commit
6743eeb89c
1 changed files with 14 additions and 0 deletions
  1. 14 0
      Babylon/Physics/Plugins/babylon.oimoJSPlugin.ts

+ 14 - 0
Babylon/Physics/Plugins/babylon.oimoJSPlugin.ts

@@ -188,6 +188,7 @@ module BABYLON {
          * @param mesh
          */
         public updateBodyPosition = function (mesh: AbstractMesh): void {
+
             for (var index = 0; index < this._registeredMeshes.length; index++) {
                 var registeredMesh = this._registeredMeshes[index];
                 if (registeredMesh.mesh === mesh || registeredMesh.mesh === mesh.parent) {
@@ -196,6 +197,19 @@ module BABYLON {
                     body.setOrientation(mesh.rotation.x, mesh.rotation.y, mesh.rotation.z);
                     return;
                 }
+                // Case where the parent has been updated
+                if (registeredMesh.mesh.parent === mesh) {
+                    mesh.computeWorldMatrix(true);
+                    registeredMesh.mesh.computeWorldMatrix(true);
+
+                    var absolutePosition = registeredMesh.mesh.getAbsolutePosition();
+                    var absoluteRotation = mesh.rotation;
+
+                    var body = registeredMesh.body.body;
+                    body.setPosition(absolutePosition.x, absolutePosition.y, absolutePosition.z);
+                    body.setOrientation(absoluteRotation.x, absoluteRotation.y, absoluteRotation.z);
+                    return;
+                }
             }
         }