cocos 3.7 射线检测如何返回第一个碰撞的网格对象?

  • Creator 版本:3.7

  • 目标平台:WIN10 chrome

  • 重现方式:

  • 首个报错:

  • 之前哪个版本是正常的:

  • 手机型号:

  • 手机浏览器:

  • 编辑器操作系统:WIN10

  • 重现概率:

const touch = event.touch!;

    this.cameraCom.screenPointToRay(touch.getLocationX(), touch.getLocationY(), this._ray);

    if (PhysicsSystem.instance.raycast(this._ray)) {

        const raycastResults = PhysicsSystem.instance.raycastResults;

        for (let i = 0; i < raycastResults.length; i++) {

            const item = raycastResults[i];

            for(let i005=0;i005<this.targetNode.length;i005++){

                if (item.collider.node == this.targetNode[i005]) {

                   

                    console.log( "click:" +item.collider.node.name);

                    break;

                }

            }

        }

        console.log(" ");

    } else {

        console.log('raycast does not hit the target node !');

    }

这个API的射线检测法返回的结果不能体现出第一个碰撞到的网格,请问有没有碰撞后不漏的并且返回第一个被碰撞网格的API?

这个检测算法好像返回的不是最近的那个,你可以看看文档,应该是只能获取所有的然后再判断距离

if (PhysicsSystem.instance.raycastClosest(_ray)) {
const r = PhysicsSystem.instance.raycastClosestResult;
return r;
} else {
return null;
}

1赞