Keep the same collision logic as which in v3.7.3 in physics-contact.ts of box2d-wasm/box2d-jsb physics-2d backend. (#18662)

This commit is contained in:
tangkai
2025-04-25 16:45:27 +08:00
committed by GitHub
parent f6d5707fd1
commit d7352b2d9b
2 changed files with 14 additions and 32 deletions
+7 -25
View File
@@ -218,39 +218,21 @@ export class PhysicsContact implements IPhysics2DContact {
}
emit (contactType: string): void {
let func = '';
switch (contactType) {
case Contact2DType.BEGIN_CONTACT:
func = 'onBeginContact';
break;
case Contact2DType.END_CONTACT:
func = 'onEndContact';
break;
case Contact2DType.PRE_SOLVE:
func = 'onPreSolve';
break;
case Contact2DType.POST_SOLVE:
func = 'onPostSolve';
break;
default:
break;
}
const colliderA = this.colliderA;
const colliderB = this.colliderB;
const bodyA = colliderA!.body;
const bodyB = colliderB!.body;
const hasListenerA = colliderA?.body?.enabledContactListener;
const hasListenerB = colliderB?.body?.enabledContactListener;
if (bodyA!.enabledContactListener) {
colliderA?.emit(contactType, colliderA, colliderB, this);
if (hasListenerA) {
colliderA.emit(contactType, colliderA, colliderB, this);
}
if (bodyB!.enabledContactListener) {
colliderB?.emit(contactType, colliderB, colliderA, this);
if (hasListenerB) {
colliderB.emit(contactType, colliderB, colliderA, this);
}
if (bodyA!.enabledContactListener || bodyB!.enabledContactListener) {
if (hasListenerA || hasListenerB) {
PhysicsSystem2D.instance.emit(contactType, colliderA, colliderB, this);
}
@@ -209,18 +209,18 @@ export class PhysicsContact implements IPhysics2DContact {
const colliderA = this.colliderA;
const colliderB = this.colliderB;
const bodyA = colliderA!.body;
const bodyB = colliderB!.body;
const hasListenerA = colliderA?.body?.enabledContactListener;
const hasListenerB = colliderB?.body?.enabledContactListener;
if (bodyA!.enabledContactListener) {
colliderA?.emit(contactType, colliderA, colliderB, this);
if (hasListenerA) {
colliderA.emit(contactType, colliderA, colliderB, this);
}
if (bodyB!.enabledContactListener) {
colliderB?.emit(contactType, colliderB, colliderA, this);
if (hasListenerB) {
colliderB.emit(contactType, colliderB, colliderA, this);
}
if (bodyA!.enabledContactListener || bodyB!.enabledContactListener) {
if (hasListenerA || hasListenerB) {
PhysicsSystem2D.instance.emit(contactType, colliderA, colliderB, this);
}