testPoint一直返回null

需要在点击时候判断是否点击到物理碰撞体,PhysicsManager 里的testPoint一直都是返回null不知道哪里出错了,大佬帮看看。
代码:
touchStart(event : cc.Event.EventTouch) {

    let touchLoc = event.getLocation();
   
    let result = cc.director.getPhysicsManager().testPoint(cc.p(touchLoc.x, touchLoc.y));
    console.log('接触时碰撞结果为 :'+result);
    if(result) {
        return false;
    }
  
    return true;
}

请问题主解决了吗,遇到同样的问题。。。

是引擎做了判断,碰撞类型为动态才可以生效。。。。

    cc.PhysicsAABBQueryCallback.prototype.ReportFixture = function (fixture) {
        var body = fixture.GetBody();
        if (this._isPoint) {
            if (fixture.TestPoint(this._point)) {
                this._fixtures.push(fixture);
                // We are done, terminate the query.
                return false;
            }
        }
        else {
            this._fixtures.push(fixture);
        }
        // True to continue the query, false to terminate the query.
        return true;
    };

找个地方执行下就可以了

源码判断了刚体是不是dynamic

https://github.com/cocos-creator/engine/blob/master/cocos2d/core/physics/platform/CCPhysicsAABBQueryCallback.js

1赞

那这怎么解决呀。。。改C++源码?

很蛋疼的设定啊,引擎开发组咋想的哦,难道static的就不是刚体啦?

hi,你好, PhysicsAABBQueryCallback 这个类需要引用引擎代码,需要被覆盖,我们的代码可以引用引擎代码吗?

没人回答吗,开发组为什么只加动态的,是因为静态的手动遍历判断更快吗