소스 검색

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 7 년 전
부모
커밋
2d28b76630
1개의 변경된 파일13개의 추가작업 그리고 2개의 파일을 삭제
  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);
             }