3.2射线检测问题,无法检测到Box

  • Creator 版本:

  • 目标平台:

  • 重现方式:

  • 首个报错:

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

  • 手机型号:

  • 手机浏览器:

  • 编辑器操作系统:

  • 重现概率:

[NewProject_3.zip|attachment](upload://7YTWHuTL6Cz41JLlNPgw6MRWB5z.zip) (1.2 MB)

求助官方大大

const outRay2 = geometry.Ray.create(pos.x, pos.y, pos.z, dir.x, dir.y, dir.z);

    if (PhysicsSystem.instance.raycast(outRay2)) {

        console.log("99996666666666669999")

        const r = PhysicsSystem.instance.raycastResults;

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

            const item = r[i];

            console.log(item)

            console.log("-----------------------")

        }

    }

就是简单的往人物前方发射射线,检测前方的Cube,Box加了,但是PhysicsSystem.instance.raycast(outRay2)进不来,是要设置什么吗

同问
···
start() {

    this.cameraCom.screenPointToRay(0, 0, this.outRay);

    console.log(PhysicsSystem.instance.raycast(this.outRay))

    const r = PhysicsSystem.instance.raycastResults;

    console.log(r)

}

···

找到了,感觉是cocos的bug,在onload和start中是不能使用ray的会无效。

    start() {
        // [3]
        // let ray = new geometry.Ray(0, 0, 100, 0, 0, -1)
        systemEvent.on(SystemEvent.EventType.MOUSE_DOWN, this.onMouseDown, this);
        console.log('onStart')
        this.castRay(v2(480, 320));

    }
    onLoad(){
        console.log('onLoad')
        this.castRay(v2(480, 320));
    }
    // update (deltaTime: number) {
    //     // [4]
    // }
    castRay(screenXY: Vec2) {
        let ray = this.cameraCom.screenPointToRay(screenXY.x, screenXY.y)
        PhysicsSystem.instance.raycast(ray)
        console.log(ray)
        console.log(PhysicsSystem.instance.raycastResults)
    }
    onMouseDown(event: EventMouse) {
        let clickPos = event.getLocation();
        console.log('Click pos', clickPos)
        // this.castRay(clickPos)
        console.log('onClick')
        this.castRay(v2(480, 320));
    }

image

对,这个射线有延迟我也是醉了,在update中是可以

有延迟是指?

是我这边之前写错了,没有延迟,自己的调用有问题,打扰了。。。