3.x版本射线检测的mask不起效

let mask = 0x0000006;

    console.log(mask)

    //基于物理碰撞器的射线检测

    if (PhysicsSystem.instance.raycastClosest(outRay,mask)) {

        console.log("PhysicsSystemTrue");

        const item = PhysicsSystem.instance.raycastClosestResult;

        console.log(item.collider.name,item.collider.node.layer);

    }else{

        console.log("PhysicsSystemfalse");

    }

我定义的layer分别是1号和2号,我按掩码的方式去定义mask的值
然而当mask = 0x0000006检测不了任何碰撞体,mask = 0x000000f则正常,当mask = 0x000000e又检测不到任何东西
有点摸不着头脑,请问这是bug还是我的使用方式错误?

1赞

这是因为你把mask算错了,layer为1和2,1的mask是1<<0=0x0000001,2的mask是1<<1=0x0000002。
你可能以为default是1<<0,其实他是0xffffffff所有layer的组合。


所以你的mask应该定义为0x0000003