Parcourir la source

Objects with their parent object now use their absolute position
This allows moving the parent object and get the transformation but yet using the physics engine with child meshes.

Raanan Weber il y a 7 ans
Parent
commit
2d28b76630
1 fichiers modifiés avec 13 ajouts et 2 suppressions
  1. 13 2
      src/Physics/babylon.physicsImpostor.ts

+ 13 - 2
src/Physics/babylon.physicsImpostor.ts

@@ -380,7 +380,13 @@ module BABYLON {
             if (!this._physicsEngine) {
                 return;
             }
-            this.object.position.subtractToRef(this._deltaPosition, this._tmpPositionWithDelta);
+
+            if (this._options.ignoreParent && this.object.parent) {
+                this._tmpPositionWithDelta.copyFrom(this.object.getAbsolutePosition());
+                //this.object.getAbsolutePosition().subtractToRef(this._deltaPosition, this._tmpPositionWithDelta);
+            } else {
+                this.object.position.subtractToRef(this._deltaPosition, this._tmpPositionWithDelta);
+            }
             //conjugate deltaRotation
             if (this.object.rotationQuaternion) {
                 if (this._deltaRotationConjugated) {
@@ -413,7 +419,12 @@ module BABYLON {
 
             this._physicsEngine.getPhysicsPlugin().setTransformationFromPhysicsBody(this);
 
-            this.object.position.addInPlace(this._deltaPosition)
+            if (this._options.ignoreParent && this.object.parent) {
+                this.object.position.subtractInPlace(this.object.parent.getAbsolutePosition());
+            } else {
+                this.object.position.addInPlace(this._deltaPosition)
+            }
+
             if (this._deltaRotation && this.object.rotationQuaternion) {
                 this.object.rotationQuaternion.multiplyInPlace(this._deltaRotation);
             }