Raycast is not work

Please tell me what could be wrong in the code that RayCasting stopped working for me?

if (this.context.input.getPointerDown(0)) {
            console.log("dsad");
            const hit = this.context.physics.engine?.raycast();
            if (hit && this.tweenB == false) {
                this._tweenA?.start();
                this.tweenB = true;
                showBalloonMessage('hit ' + hit.collider.name);
            }
            if (hit)
            {
            this._tweenB?.start();
            this.tweenB = false;
            }
          }

Original Post on Discord

by user 1101049107931480066

Hi, do you have any colliders in your scene?

You can add ?showcolliders to your url to visualize them

no collider on scene.

by user 1101049107931480066

const hit = this.context.physics.engine?.raycast()?.collider; ?

by user 1101049107931480066

this.context.input.getPointerDown(0)
this piece of code is not working

by user 1101049107931480066

Without colliders your physics raycast can not hit anything.
If you want to raycast against threejs meshes then use this.context.physics.raycast (not physics.engine.raycast)

how can i do it with collider?

by user 1101049107931480066

You just add colliders in unity or blender to your scene where you need them (box, sphere, capsule or meshcolliders) and then raycast with this.context.physics.engine?.raycast()

But how can I write in the code so that it understands which collider should work? I didn’t find it in the documentation

by user 1101049107931480066

You can not ignore certain colliders right now as you can with unity because raycast layers are not exposed / implemented yet.
When you hit something you can only use the name or the components on the gameObject to figure out if you hit what you wanted but that might not be enough depending on your usecase (not sure what you’re building, maybe you can describe what you need)

(i might be mistaken, i think raycast has a way to filter hits via a callback but im currently on a train, i can check again later for you to give you a more precise answer)

With the non physics raycast (this.context.physics.raycast) you can add RaycastOptions as an argument to ignore e.g. objects on specific layers, e.g. unity’s layer for IgnoreRaycast is ignored by default)

that’s what he meant (hit?.collider.name == “holly”)

by user 1101049107931480066

For example. You can check for tags or layers the same way. Or by getting a specific component via e.g. hit.collider.gameObject.getComponent or getComponentInParent

But how can I make sure that I understand the presence of a tag?

by user 1101049107931480066

collider.tag == "MyTag"

Hi, i’m checking the rayscast and i’m trying to understand the RayCastOptions, could you give an example of his use ? If I want to set the origin point and the vector direction and maybe the length of the raycast.
And for example, this statement hit?.collider.layer is posibble ?
Thank you .

by user 632418299711324161

For setting origin and direction just pass in a THREE.Ray (it has an origin and a direction)

For length you can set the minDistance and maxDistance