mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-19 14:52:40 +08:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user