Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue that onControllerTriggerEnter may not be triggered #17616

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions cocos/physics/bullet/bullet-world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import { BulletShape } from './shapes/bullet-shape';
import { ArrayCollisionMatrix } from '../utils/array-collision-matrix';
import { TupleDictionary } from '../utils/tuple-dictionary';
import { TriggerEventObject, CollisionEventObject, CC_V3_0, CC_V3_1, CC_V3_2, CC_COLOR_0, BulletCache, CharacterTriggerEventObject } from './bullet-cache';

Check warning on line 31 in cocos/physics/bullet/bullet-world.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 155. Maximum allowed is 150
import { bullet2CocosVec3, cocos2BulletQuat, cocos2BulletVec3 } from './bullet-utils';
import { IRaycastOptions, IPhysicsWorld } from '../spec/i-physics-world';
import { PhysicsRayResult, PhysicsMaterial, CharacterControllerContact, EPhysicsDrawFlags } from '../framework';
Expand Down Expand Up @@ -135,6 +135,7 @@
readonly ccts: BulletCharacterController[] = [];
readonly constraints: BulletConstraint[] = [];
readonly triggerArrayMat = new ArrayCollisionMatrix();
readonly characterControllerArrayMat = new ArrayCollisionMatrix();
readonly collisionArrayMat = new ArrayCollisionMatrix();
readonly contactsDic = new TupleDictionary();
readonly oldContactsDic = new TupleDictionary();
Expand Down Expand Up @@ -180,6 +181,7 @@
(this as any).ccts = null;
(this as any).constraints = null;
(this as any).triggerArrayMat = null;
(this as any).characterControllerArrayMat = null;
(this as any).collisionArrayMat = null;
(this as any).contactsDic = null;
(this as any).oldContactsDic = null;
Expand Down Expand Up @@ -682,11 +684,11 @@
if (collider && characterController) {
const isTrigger = collider.isTrigger;
if (isTrigger) {
if (this.triggerArrayMat.get(shape.id, cct.id)) {
if (this.characterControllerArrayMat.get(shape.id, cct.id)) {
CharacterTriggerEventObject.type = 'onControllerTriggerStay';
} else {
CharacterTriggerEventObject.type = 'onControllerTriggerEnter';
this.triggerArrayMat.set(shape.id, cct.id, true);
this.characterControllerArrayMat.set(shape.id, cct.id, true);
}
CharacterTriggerEventObject.impl = data.impl; //btPersistentManifold
CharacterTriggerEventObject.collider = collider;
Expand Down Expand Up @@ -718,7 +720,7 @@
const isTrigger = collider.isTrigger;
if (this.cctContactsDic.getDataByKey(key) == null) {
if (isTrigger) {
if (this.triggerArrayMat.get(shape.id, cct.id)) {
if (this.characterControllerArrayMat.get(shape.id, cct.id)) {
CharacterTriggerEventObject.type = 'onControllerTriggerExit';
CharacterTriggerEventObject.collider = collider;
CharacterTriggerEventObject.characterController = characterController;
Expand All @@ -728,7 +730,7 @@
CharacterTriggerEventObject.characterController = characterController;
characterController.emit(CharacterTriggerEventObject.type, CharacterTriggerEventObject);

this.triggerArrayMat.set(shape.id, cct.id, false);
this.characterControllerArrayMat.set(shape.id, cct.id, false);
this.cctOldContactsDic.set(shape.id, cct.id, null);
this._needSyncAfterEvents = true;
}
Expand Down
Loading