CC v3 How cast a ray in 3d world

How can i cast a ray with cocos creator 3
It’s documents doesn’t help me
When i using the
geometry.ray
VS indicate that was deprecated

Do you already refer to this document?

https://docs.cocos.com/creator/3.0/manual/en/physics/physics-raycast.html

1 Like

Thank you , yes i try that before, but i can’t cast any ray and detect collision.

This blog post helped me
https://www.programmersought.com/article/40684242911/

I just changed first line :

 ray = new geometry.Ray();
  start() {
        systemEvent.on(SystemEventType.MOUSE_DOWN, this.onMouseDown, this);
    }
            onMouseDown(event: EventMouse) {

        this.camera_3d.screenPointToRay(event.getLocationX(), event.getLocationY(), this.ray);
        if (PhysicsSystem.instance.raycast(this.ray)) {
            const r = PhysicsSystem.instance.raycastResults;
            console.log(r[0].collider.node.name);
            this.cube2?.setPosition(r[0].hitPoint);
}        }

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.