From 081867183a8bb10db000c24007cf88974cffd306 Mon Sep 17 00:00:00 2001 From: "jiaxin.lai" Date: Tue, 23 Apr 2019 13:06:25 +0800 Subject: [PATCH] =?UTF-8?q?fix=20bug:=20"BoxCollider=20=E4=BC=98=E5=85=88?= =?UTF-8?q?=E7=BA=A7=E5=BF=85=E9=A1=BB=E9=AB=98=E4=BA=8E=20RigidBody"=20(#?= =?UTF-8?q?4270)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cocos/3d/framework/physics/collider-component.ts | 12 ++++++++---- cocos/3d/framework/physics/rigid-body-component.ts | 11 +++++++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/cocos/3d/framework/physics/collider-component.ts b/cocos/3d/framework/physics/collider-component.ts index 69de4169dd..04c97ee57e 100644 --- a/cocos/3d/framework/physics/collider-component.ts +++ b/cocos/3d/framework/physics/collider-component.ts @@ -57,12 +57,16 @@ export class ColliderComponentBase extends PhysicsBasedComponent { public __preload () { super.__preload(); + } + + public onLoad () { if (this.sharedBody) { this.sharedBody.transfromSource = ETransformSource.SCENE; + // useGravity属性默认是为true的 this.sharedBody.body.setUseGravity(false); + this.center = this._center; + this.isTrigger = this._triggered; } - this.center = this._center; - this.isTrigger = this._triggered; } // public lateUpdate () { @@ -95,7 +99,7 @@ export class ColliderComponentBase extends PhysicsBasedComponent { } @ccclass('cc.BoxColliderComponent') -@executionOrder(100) +@executionOrder(98) @menu('Components/BoxColliderComponent') @executeInEditMode export class BoxColliderComponent extends ColliderComponentBase { @@ -140,7 +144,7 @@ export class BoxColliderComponent extends ColliderComponentBase { } @ccclass('cc.SphereColliderComponent') -@executionOrder(100) +@executionOrder(98) @menu('Components/SphereColliderComponent') @executeInEditMode export class SphereColliderComponent extends ColliderComponentBase { diff --git a/cocos/3d/framework/physics/rigid-body-component.ts b/cocos/3d/framework/physics/rigid-body-component.ts index 325740195f..9c67442b0b 100644 --- a/cocos/3d/framework/physics/rigid-body-component.ts +++ b/cocos/3d/framework/physics/rigid-body-component.ts @@ -20,7 +20,7 @@ const NonRigidBodyProperties = { }; @ccclass('cc.RigidBodyComponent') -@executionOrder(101) +@executionOrder(99) @menu('Components/RigidBodyComponent') @executeInEditMode export class RigidBodyComponent extends PhysicsBasedComponent { @@ -56,8 +56,15 @@ export class RigidBodyComponent extends PhysicsBasedComponent { public __preload () { super.__preload(); - this.sharedBody!.transfromSource = ETransformSource.PHYSIC; + } + + public onLoad () { + /** + * 此处设置刚体属性是因为__preload不受executionOrder的顺序影响, + * 从而导致ColliderComponent后添加会导致刚体的某些属性被重写 + */ if (this.sharedBody) { + this.sharedBody.transfromSource = ETransformSource.PHYSIC; this.mass = this._mass; this.linearDamping = this._linearDamping; this.angularDamping = this._angularDamping;