Skip to content

Commit 375ad81

Browse files
committed
修复 character controller 的 group/mask 没有正确设置的问题
1 parent c04e6e0 commit 375ad81

5 files changed

Lines changed: 26 additions & 10 deletions

File tree

cocos/physics/physx/character-controllers/physx-box-character-controller.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,12 @@ export class PhysXBoxCharacterController extends PhysXCharacterController implem
6767
controllerDesc.position = { x: v3_0.x, y: v3_0.y, z: v3_0.z };//PxExtendedVec3
6868
controllerDesc.setMaterial(pxMtl);
6969
controllerDesc.setReportCallback(PX.PxUserControllerHitReport.implement(physxWorld.callback.controllerHitReportCB));
70-
this._impl = PX.createBoxCharacterController(physxWorld.controllerManager, controllerDesc);
70+
const impl = PX.createBoxCharacterController(physxWorld.controllerManager, controllerDesc);
71+
this.setImpl(impl);
7172

72-
if (this._impl.$$) {
73-
PX.IMPL_PTR[this._impl.$$.ptr] = this;
74-
const shapePtr = this._impl.getShape().$$.ptr;
73+
if (impl.$$) {
74+
PX.IMPL_PTR[impl.$$.ptr] = this;
75+
const shapePtr = impl.getShape().$$.ptr;
7576
PX.IMPL_PTR[shapePtr] = this;
7677
}
7778

cocos/physics/physx/character-controllers/physx-capsule-character-controller.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,12 @@ export class PhysXCapsuleCharacterController extends PhysXCharacterController im
6868
controllerDesc.position = { x: v3_0.x, y: v3_0.y, z: v3_0.z };//PxExtendedVec3
6969
controllerDesc.setMaterial(pxMtl);
7070
controllerDesc.setReportCallback(PX.PxUserControllerHitReport.implement(physxWorld.callback.controllerHitReportCB));
71-
this._impl = PX.createCapsuleCharacterController(physxWorld.controllerManager, controllerDesc);
71+
const impl = PX.createCapsuleCharacterController(physxWorld.controllerManager, controllerDesc);
72+
this.setImpl(impl);
7273

73-
if (this._impl.$$) {
74-
PX.IMPL_PTR[this._impl.$$.ptr] = this;
75-
const shapePtr = this._impl.getShape().$$.ptr;
74+
if (impl.$$) {
75+
PX.IMPL_PTR[impl.$$.ptr] = this;
76+
const shapePtr = impl.getShape().$$.ptr;
7677
PX.IMPL_PTR[shapePtr] = this;
7778
}
7879

cocos/physics/physx/character-controllers/physx-character-controller.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { PhysXWorld } from '../physx-world';
3131
import { PhysXShape } from '../shapes/physx-shape';
3232
import { degreesToRadians } from '../../../core/utils/misc';
3333
import { TransformBit } from '../../../scene-graph';
34+
import { PhysXFilterData } from '../filter-data';
3435

3536
const v3_0 = new Vec3(0, 0, 0);
3637
const v3_1 = new Vec3(0, 0, 0);
@@ -41,7 +42,7 @@ export class PhysXCharacterController implements IBaseCharacterController {
4142
protected _impl: any = null;
4243
protected _comp: CharacterController = null as any;
4344
private _pxCollisionFlags = 0;//: PX.PxControllerCollisionFlags;
44-
private _filterData: any;
45+
private _filterData: PhysXFilterData;
4546
private _queryFilterCB: any = null;
4647
protected _word3 = 0;
4748
protected _overlapRecovery = true;
@@ -85,6 +86,7 @@ export class PhysXCharacterController implements IBaseCharacterController {
8586
this._filterData.word0 = this._comp.group;
8687
const mask = PhysicsSystem.instance.collisionMatrix[group];
8788
this._filterData.word1 = mask;
89+
this.updateFilterData();
8890

8991
this.onComponentSet();
9092

@@ -292,4 +294,9 @@ export class PhysXCharacterController implements IBaseCharacterController {
292294
// this._impl.setQueryFilterData(filterData);//set inside move()
293295
this._impl.setSimulationFilterData(this.filterData);
294296
}
297+
298+
protected setImpl (impl: any): void {
299+
this._impl = impl;
300+
this.updateFilterData();
301+
}
295302
}

cocos/physics/physx/filter-data.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export interface PhysXFilterData {
2+
word0: number;
3+
word1: number;
4+
word2: number;
5+
word3: number;
6+
}

cocos/physics/physx/physx-shared-body.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { ERigidBodyType, PhysicsSystem } from '../framework';
3737
import { PhysXJoint } from './joints/physx-joint';
3838
import { PhysicsGroup } from '../framework/physics-enum';
3939
import { Node } from '../../scene-graph';
40+
import { PhysXFilterData } from './filter-data';
4041

4142
/** @mangle */
4243
export class PhysXSharedBody {
@@ -89,7 +90,7 @@ export class PhysXSharedBody {
8990
private _dynamicActor!: PhysX.RigidActor | any;
9091
private _staticActor!: PhysX.RigidActor | any;
9192
private _wrappedBody: PhysXRigidBody | null = null;
92-
private _filterData: any;
93+
private _filterData: PhysXFilterData;
9394

9495
set reference (v: boolean) {
9596
this._ref = v ? this._ref + 1 : this._ref - 1;

0 commit comments

Comments
 (0)