@@ -118,7 +118,7 @@ export class ColliderBase extends Component {
118
118
public set inertia ( value : number ) {
119
119
this . _inertia = value ;
120
120
if ( ! this . _useAutoMass ) {
121
- Physics2D . I . _factory . set_rigidBody_Mass ( this . _box2DBody , this . _mass , this . _centerOfMass , this . _inertia , this . _massData ) ;
121
+ this . _box2DBody && Physics2D . I . _factory . set_rigidBody_Mass ( this . _box2DBody , this . _mass , this . _centerOfMass , this . _inertia , this . _massData ) ;
122
122
}
123
123
}
124
124
@@ -128,7 +128,7 @@ export class ColliderBase extends Component {
128
128
*/
129
129
public get centerOfMass ( ) : IV2 | Vector2 {
130
130
let center ;
131
- if ( this . _useAutoMass ) {
131
+ if ( this . _useAutoMass && this . _box2DBody ) {
132
132
center = Physics2D . I . _factory . get_rigidBody_Center ( this . _box2DBody ) ;
133
133
this . _centerOfMass . x = center . x ;
134
134
this . _centerOfMass . y = center . y ;
@@ -145,7 +145,7 @@ export class ColliderBase extends Component {
145
145
this . _centerOfMass . y = value . y ;
146
146
}
147
147
if ( ! this . _useAutoMass ) {
148
- Physics2D . I . _factory . set_rigidBody_Mass ( this . _box2DBody , this . _mass , this . _centerOfMass , this . _inertia , this . _massData ) ;
148
+ this . _box2DBody && Physics2D . I . _factory . set_rigidBody_Mass ( this . _box2DBody , this . _mass , this . _centerOfMass , this . _inertia , this . _massData ) ;
149
149
}
150
150
}
151
151
@@ -155,7 +155,7 @@ export class ColliderBase extends Component {
155
155
*/
156
156
public get mass ( ) : number {
157
157
let mass ;
158
- if ( this . _useAutoMass ) {
158
+ if ( this . _useAutoMass && this . _box2DBody ) {
159
159
mass = Physics2D . I . _factory . get_rigidBody_Mass ( this . _box2DBody ) ;
160
160
} else {
161
161
mass = this . _mass ;
@@ -165,8 +165,7 @@ export class ColliderBase extends Component {
165
165
public set mass ( value : number ) {
166
166
this . _mass = value ;
167
167
if ( ! this . _useAutoMass ) {
168
- Physics2D . I . _factory . set_rigidBody_Mass ( this . _box2DBody , this . _mass , this . _centerOfMass , this . _inertia , this . _massData ) ;
169
-
168
+ this . _box2DBody && Physics2D . I . _factory . set_rigidBody_Mass ( this . _box2DBody , this . _mass , this . _centerOfMass , this . _inertia , this . _massData ) ;
170
169
}
171
170
}
172
171
@@ -179,19 +178,21 @@ export class ColliderBase extends Component {
179
178
}
180
179
public set useAutoMass ( value : boolean ) {
181
180
this . _useAutoMass = value ;
182
- Physics2D . I . _factory . set_rigidBody_Mass ( this . _box2DBody , this . _mass , this . _centerOfMass , this . _inertia , this . _massData ) ;
181
+ this . _box2DBody && Physics2D . I . _factory . set_rigidBody_Mass ( this . _box2DBody , this . _mass , this . _centerOfMass , this . _inertia , this . _massData ) ;
183
182
}
184
183
185
184
/**
186
185
* @zh 当前碰撞体在物理世界中是否在激活状态
187
186
*/
188
187
public get isAwake ( ) : boolean {
189
- this . _isAwake = Physics2D . I . _factory . get_rigidBody_IsAwake ( this . _box2DBody ) ;
188
+ if ( this . _box2DBody ) {
189
+ this . _isAwake = Physics2D . I . _factory . get_rigidBody_IsAwake ( this . _box2DBody ) ;
190
+ }
190
191
return this . isAwake ;
191
192
}
192
193
public set isAwake ( value : boolean ) {
193
194
this . _isAwake = value ;
194
- Physics2D . I . _factory . set_rigidBody_Awake ( this . _box2DBody , value ) ;
195
+ this . _box2DBody && Physics2D . I . _factory . set_rigidBody_Awake ( this . _box2DBody , value ) ;
195
196
}
196
197
197
198
/**
@@ -231,7 +232,7 @@ export class ColliderBase extends Component {
231
232
set x ( value : number ) {
232
233
if ( this . _x == value ) return ;
233
234
this . _x = value ;
234
- this . _updateTransformFromRender ( ) ;
235
+ this . _needupdataShapeAttribute ( ) ;
235
236
}
236
237
237
238
/**
@@ -245,7 +246,7 @@ export class ColliderBase extends Component {
245
246
set y ( value : number ) {
246
247
if ( this . _y == value ) return ;
247
248
this . _y = value ;
248
- this . _updateTransformFromRender ( ) ;
249
+ this . _needupdataShapeAttribute ( ) ;
249
250
}
250
251
251
252
/**
@@ -300,12 +301,13 @@ export class ColliderBase extends Component {
300
301
return this . owner . globalTrans . localToGlobal ( x , y ) ;
301
302
}
302
303
304
+
303
305
/**
304
- * @zh 从渲染更新碰撞体的位置
306
+ * @internal
307
+ * @en Refresh the physics world collision information after the collision body parameters change.
308
+ * @zh 碰撞体参数发生变化后,刷新物理世界碰撞信息
305
309
*/
306
- private _updateTransformFromRender ( ) {
307
- var sp : Sprite = this . owner ;
308
- Physics2D . I . _factory . set_RigibBody_Transform ( this . _box2DBody , sp . globalTrans . x , sp . globalTrans . y , Utils . toRadian ( this . owner . globalTrans . rotation ) ) ;
310
+ _refresh ( ) : void {
309
311
}
310
312
311
313
/**@internal */
@@ -431,7 +433,15 @@ export class ColliderBase extends Component {
431
433
432
434
/**@internal @deprecated 通知rigidBody 更新shape 属性值 */
433
435
protected _needupdataShapeAttribute ( ) : void {
434
- this . _rigidbody && this . createShape ( this . _rigidbody ) ;
436
+ //兼容模式下使用,设置类似BoxCollider的偏移方式
437
+ if ( this . _rigidbody && this . _rigidbody . applyOwnerColliderComponent ) {
438
+ this . createShape ( this . _rigidbody ) ;
439
+ }
440
+ //非dynamic类型下可以直接设置位置
441
+ if ( this . _type != "dynamic" ) {
442
+ var sp : Sprite = this . owner ;
443
+ this . _box2DBody && Physics2D . I . _factory . set_RigibBody_Transform ( this . _box2DBody , sp . globalTrans . x , sp . globalTrans . y , Utils . toRadian ( this . owner . globalTrans . rotation ) ) ;
444
+ }
435
445
}
436
446
437
447
// ----------------------- 已废弃 deprecated ------------------------
0 commit comments