CocosCreator3.0.0+版本的2D物体(图片之类的),碰撞处理回调,是怎么处理的

懵逼了,3.0以下的2个物体只加collider就能出发碰撞事件回调(用Builtin 模块也没得用),3.0.的需要怎么改,可以有回调,试了文档没成功~~

import { _decorator, Component, Node, Collider2D, Contact2DType, PhysicsSystem2D, EventTouch } from ‘cc’;
import { DEBUG } from ‘cce.env’;
const { ccclass, property } = _decorator;

@ccclass(‘Test’)
export class Test extends Component {
/* class member could be defined like this */
// dummy = ‘’;

/* use `property` decorator if your want the member to be serializable */
// @property
// serializableDummy = 0;

start () {

    //3.0以下
    // cc.director.getCollisionManager().enabled=true;
    // cc.director.getCollisionManager().enabledDebugDraw = true;
    // this.node.on(cc.Node.EventType.TOUCH_MOVE, function (event:cc.Event.EventTouch ) {
    //     var delta = event.touch.getDelta();
    //         this.x += delta.x;
    //         this.y += delta.y;
    //     }, 
    // this.node);

    //3.0+
    let self = this;
    this.node.on( Node.EventType.TOUCH_MOVE, (event:EventTouch) =>{
        let delta = event.touch.getDelta();
        let x= this.node.position.x;
        let y= this.node.position.y;
        this.node.setPosition(x+=delta.x,y+=delta.y,0);
    }  ,this)


    let collider = this.getComponent(Collider2D);
    if (collider) {
         collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
         collider.on(Contact2DType.END_CONTACT, this.onEndContact, this);
         collider.on(Contact2DType.PRE_SOLVE, this.onPreSolve, this);
         collider.on(Contact2DType.POST_SOLVE, this.onPostSolve, this);
    }

    // // 注册全局碰撞回调函数
    if (PhysicsSystem2D.instance) {
        // PhysicsSystem2D.instance.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
        // PhysicsSystem2D.instance.on(Contact2DType.END_CONTACT, this.onEndContact, this);
        // PhysicsSystem2D.instance.on(Contact2DType.PRE_SOLVE, this.onPreSolve, this);
        // PhysicsSystem2D.instance.on(Contact2DType.POST_SOLVE, this.onPostSolve, this);
    }
}

//#region 3.0++
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
    // 只在两个碰撞体开始接触时被调用一次
    console.log('onBeginContact');
}
onEndContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
    // 只在两个碰撞体结束接触时被调用一次
    console.log('onEndContact');
}
onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
    // 每次将要处理碰撞体接触逻辑时被调用
    console.log('onPreSolve');
}
onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
    // 每次处理完碰撞体接触逻辑时被调用
    console.log('onPostSolve');
}
//#endregion


//#region 3.0以下
onCollisionEnter(other:any,self:any){
    console.log("进入",other);
    console.log("进入",self);
  
}
onCollisionStay(other:any,self:any){
    console.log("保持",other);
    console.log("保持",self);
  
}
onCollisionExit(other:any,self:any){
    console.log("离开",other);
    console.log("离开",self);
}
//#endregion

}


是没开启碰撞监听的原因么?

一个加2d刚体 开监听了 没用

不是要先分组的吗?

目前都在default下了,分组也试了~ 就很神奇,如果两个物体都加上2d刚体,一个type:dynamic 一个ik的,就能触发,然后把刚体组件关掉,还能有效果。。。
引擎关掉重启也能有效果,结束碰撞离开也没试到qaq

NewProject_1.zip (25.7 KB)
3.0.1版本的 ~~看看

拖动离开就也没得法触发了~

兄弟这个问题解决了吗,现在我也遇到这个问题,一定要加了刚体才能监听到事件回调 ,整的有点懵

引擎版本是 3.0.0 还是3.0.1?
如果是3.0.0,参考这个修复pr: https://github.com/cocos-creator/engine/pull/8294

该主题在最后一个回复创建后14天后自动关闭。不再允许新的回复。